Files
Discord-Radio-Bot/bot.py
Logan Cusano ba81d70669 Added new 'modules' folder for cogs (extensions)
Added 420 cog
Updated help menu
Updated README
2021-12-05 03:57:41 -05:00

69 lines
2.4 KiB
Python

import os
import discord
import sound
from discord.ext import commands
class Bot(commands.Bot):
def __init__(self, bot_token, device_id, device_name, command_prefix='>!'):
commands.Bot.__init__(self, command_prefix=commands.when_mentioned_or(command_prefix))
self.DEVICE_ID = int(device_id)
self.DEVICE_NAME = str(device_name)
self.BOT_TOKEN = str(bot_token)
self.Devices_List = sound.query_devices().items()
self.add_commands()
self.check_for_modules()
def start_bot(self):
#self.add_cog(WillieTimer(self))
self.run(self.BOT_TOKEN)
def add_commands(self):
@self.command(help="Use this to test if the bot is alive", brief="Sends a 'pong' in response")
async def ping(ctx):
await ctx.send('pong')
@self.command(help="Use this command to join the bot to your channel", brief="Joins the voice channel that the caller is in")
async def join(ctx, *, member: discord.Member = None):
member = member or ctx.author.display_name
await self.wait_until_ready()
discord.opus.load_opus('./opus/libopus.dll')
if discord.opus.is_loaded():
stream = sound.PCMStream()
channel = ctx.author.voice.channel
await ctx.send(f"Ok {member}, I'm joining {channel}")
stream.change_device(self.DEVICE_ID)
voice_connection = await channel.connect()
voice_connection.play(discord.PCMAudio(stream))
else:
await ctx.send("Opus won't load")
@self.command(help="Use this command to have the bot leave your channel", brief="Leaves the current voice channel")
async def leave(ctx):
await ctx.voice_client.disconnect()
def check_device(self):
for device, index in self.Devices_List:
if int(index) == self.DEVICE_ID and str(device) == self.DEVICE_NAME:
return True
for device, index in self.Devices_List:
if str(device) == self.DEVICE_NAME:
self.DEVICE_ID = int(index)
return True
else:
return False
def check_for_modules(self):
for folder_name in os.listdir("modules"):
if os.path.exists(os.path.join("modules", folder_name, "cog.py")):
print(f"Loaded extension: {folder_name}")
self.load_extension(f"modules.{folder_name}.cog")