From cf62c42bd8c750e2def4bf6ed7d5f7cdfeef5df8 Mon Sep 17 00:00:00 2001 From: jorgef17 <87203291+jorgef17@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:26:02 -0500 Subject: [PATCH] Keep music bot connection stable --- Music.py | 9 ++++++--- README.md | 3 +++ index.py | 9 ++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Music.py b/Music.py index 8d9d38a..9bf7756 100644 --- a/Music.py +++ b/Music.py @@ -8,7 +8,9 @@ import pickle # Intents and settings +# Voice state intent is required so the bot can join and manage voice channels intents = discord.Intents.default() +intents.guilds = True intents.message_content = True intents.voice_states = True @@ -73,10 +75,9 @@ async def play_next(self, ctx): except Exception as e: print(f"Error playing audio: {str(e)}") await ctx.send(f"Error playing audio: {str(e)}") - elif not ctx.voice_client.is_playing(): + elif ctx.voice_client and not ctx.voice_client.is_playing(): await ctx.send("Queue is empty!") print("Queue is empty!") - await ctx.voice_client.disconnect() @commands.command() async def play(self, ctx, *, search): @@ -85,7 +86,9 @@ async def play(self, ctx, *, search): if not voice_channel: return await ctx.send("You're not in a voice channel!") if not ctx.voice_client: - await voice_channel.connect() + await voice_channel.connect(self_deaf=True) + elif ctx.voice_client.channel != voice_channel: + await ctx.voice_client.move_to(voice_channel) async with ctx.typing(): try: diff --git a/README.md b/README.md index b87abf9..3cf610f 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,6 @@ For the correct installation of FFmpeg on Windows we suggest using the following for the installation of the dependencies it is suggested to use pip install -r requirements +## Discord intents +Discord recently made voice state data a privileged intent. Make sure the bot token has the **Message Content** and **Voice State** intents enabled in the [Discord Developer Portal](https://discord.com/developers/applications) so commands like `!play` can join voice channels. Both `Music.py` and `index.py` already request these intents in code. + diff --git a/index.py b/index.py index 3963e22..558ac34 100644 --- a/index.py +++ b/index.py @@ -11,8 +11,11 @@ import openai -intents = discord.Intents.default() -intents.message_content = True +intents = discord.Intents.default() +intents.guilds = True +intents.message_content = True +# Voice state intent is required for connecting to and managing voice channels +intents.voice_states = True openai.api_key = 'Token Chatgpt' bot = commands.Bot(command_prefix="!", intents=intents) @@ -332,4 +335,4 @@ async def chat(ctx, *, message: str): -bot.run('Token Discord') \ No newline at end of file +bot.run('Token Discord')