Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/slashcommands #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
discord_token = "add_bot_token_here"
DISCORD_TOKEN = "add_bot_token_here"
MONGO_URI = "mongodb://mongodb:27017"
BOT_OWNER_USER_NAME = "add bot owner user name here example: name#0001"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__pycache__/
*.py[cod]
*$py.class

.idea/
# C extensions
*.so

Expand Down
47 changes: 40 additions & 7 deletions Dizplayer.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,59 @@
import os

import discord
import nest_asyncio
from discord.ext import commands
from dotenv import load_dotenv

from Listener import ListenerCog
from Music import MusicPlayerCog
import pymongo
import datetime

from Music import Music

nest_asyncio.apply()
load_dotenv()
# Get the API token from the .env file.
DISCORD_TOKEN = os.getenv("discord_token")
print(DISCORD_TOKEN)
BOT_OWNER_USER_NAME = os.getenv("BOT_OWNER_USER_NAME")
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
MONGO_URI = os.getenv("MONGO_URI")

initial_extensions = ['cogs.listener',
'cogs.music']

intents = discord.Intents().all()
bot = commands.Bot(command_prefix='!', intents=intents)

mongo_client = pymongo.MongoClient(MONGO_URI)
bot.mongo_db = mongo_client.youtube_streamer


@bot.event
async def on_guild_join(guild):
guilds = bot.mongo_db.guilds
this_guild = guilds.find_one({"guild_id": guild.id})
if this_guild:
return

inserted = guilds.insert_one({
"guild_id": guild.id,
"name": guild.name,
"volume": 5,
"authorized": False,
"added_by": {
"name": str(guild.owner),
"id": guild.owner.id
},
"created_at": datetime.datetime.utcnow()
})

guild_owner = await bot.fetch_user(guild.owner.id)
await guild_owner.send(f"You recently added me to {guild.name}. I cannot be used until authorized by whoever is running the bot. Please contact the bot admin to request authorization for your server.")

owner_name = os.getenv("BOT_OWNER_USER_NAME").split('#')[0]
discriminator = os.getenv("BOT_OWNER_USER_NAME").split('#')[1]
bot_owner = discord.utils.get(bot.get_all_members(), name=owner_name, discriminator=discriminator)
await bot_owner.send(f"A new Guild is attempting to use the bot {guild.name} ({guild.id})\n"
f"Guild owner contact: {str(guild.owner)} ({guild.owner.id})")

if __name__ == "__main__":
bot.add_cog(MusicPlayerCog(bot))
bot.add_cog(Music(bot))
bot.add_cog(ListenerCog(bot))
bot.run(DISCORD_TOKEN)
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ WORKDIR /app
COPY ./requirements.txt /app

ENV PYTHONUNBUFFERED 1

RUN apt-get -y update
RUN apt-get install -y ffmpeg
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . .

CMD ["python", "Dizplayer.py"]
COPY . .
Loading