# DragonBot.py
class DragonBot(commands.Bot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.first_start = True
self.pool = mafic.NodePool(self)
async def on_ready(self) -> None:
if self.first_start:
log.info(
f"Bot started as {self.user.name}#{self.user.discriminator} | {self.user.id}"
)
await db.set_up()
log.debug("Database setup successful")
await self.pool.create_node(
host = "localhost", port = 2333, password = "youshallnotpass", label = "Main"
)
self.first_start = False
# MusicPlayer.py
from DragonBot import DragonBot
from discord.abc import Connectable
from mafic import Player, Track
class DragonPlayer(Player[DragonBot]):
def __init__(self, client: DragonBot, channel: Connectable) -> None:
super().__init__(client, channel)
# Mafic does not provide a queue system right now, low priority.
self.queue: list[Track] = []
# m_play.py
class MaficMusicEventsCog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.slash_command(name = "join", description = "join's your voice")
async def join(self, inter: discord.ApplicationContext):
"""Join your voice channel."""
assert isinstance(inter.user, discord.Member)
if not inter.user.voice or not inter.user.voice.channel:
return await inter.response.send_message("You are not in a voice channel.")
channel = inter.user.voice.channel
# This apparently **must** only be `Client`.
await channel.connect(cls = DragonPlayer) # pyright: ignore[reportGeneralTypeIssues]
await inter.send(f"Joined {channel.mention}.")
@commands.slash_command(name = "play", description = "Play a song of your desire")
async def play(self, inter: discord.ApplicationContext, query: str):
"""Play a song.
query:
The song to search or play.
"""
assert inter.guild is not None
if not inter.guild.voice_client:
await self.join(inter)
player: DragonPlayer = (
inter.guild.voice_client
) # pyright: ignore[reportGeneralTypeIssues]
tracks = await player.fetch_tracks(query)
if not tracks:
return await inter.send("No tracks found.")
if isinstance(tracks, mafic.Playlist):
tracks = tracks.tracks
if len(tracks) > 1:
player.queue.extend(tracks[1:])
track = tracks[0]
await player.play(track)
await inter.send(f"Playing {track}")
def setup(client: DragonBot):
client.add_cog(MaficMusicEventsCog(client))
Ignoring exception in command play:
Traceback (most recent call last):
File "E:\DragonBot\venv\Lib\site-packages\discord\commands\core.py", line 124, in wrapped
ret = await coro(arg)
^^^^^^^^^^^^^^^
File "E:\DragonBot\venv\Lib\site-packages\discord\commands\core.py", line 978, in _invoke
await self.callback(self.cog, ctx, **kwargs)
File "E:\DragonBot\extensions\mafic\m_play.py", line 57, in play
await player.play(track)
File "E:\DragonBot\venv\Lib\site-packages\mafic\player.py", line 553, in play
return await self.update(
^^^^^^^^^^^^^^^^^^
File "E:\DragonBot\venv\Lib\site-packages\mafic\player.py", line 504, in update
await self._node.update(
File "E:\DragonBot\venv\Lib\site-packages\mafic\node.py", line 854, in __request
raise HTTPNotFound(text)
mafic.errors.HTTPNotFound: An HTTP error occured: {"timestamp":1676481027978,"status":404,"error":"Not Found","message":"Not Found","path":"/sessions/None/players/578446945425555464"} (404)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\DragonBot\venv\Lib\site-packages\discord\bot.py", line 1114, in invoke_application_command
await ctx.command.invoke(ctx)
File "E:\DragonBot\venv\Lib\site-packages\discord\commands\core.py", line 375, in invoke
await injected(ctx)
File "E:\DragonBot\venv\Lib\site-packages\discord\commands\core.py", line 132, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: HTTPNotFound: An HTTP error occured: {"timestamp":1676481027978,"status":404,"error":"Not Found","message":"Not Found","path":"/sessions/None/players/578446945425555464"} (404)
Version: 3.7.4
Build time: 02.02.2023 18:34:07 UTC
Branch HEAD
Commit: 8ebaba1
Commit time: 02.02.2023 18:32:05 UTC
JVM: 17.0.5
Lavaplayer 1.3.99.2-original