I’m trying to add music features to my Discord bot. I switched to wavelink since youtube-dl got blocked. The bot can join voice channels when I use the play command, but it doesn’t play any sound. No errors show up in the console, and the green speaking circle doesn’t appear next to the bot.
Here’s a simplified version of my code:
import discord
import wavelink
from discord.ext import commands
class MusicBot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
super().__init__(intents=intents, command_prefix='!')
async def setup_hook(self):
node = wavelink.Node(uri='http://example.com:2333', password='yourpassword')
await wavelink.NodePool.connect(client=self, nodes=[node])
bot = MusicBot()
@bot.command()
async def play(ctx, *, query: str):
if not ctx.voice_client:
vc = await ctx.author.voice.channel.connect(cls=wavelink.Player)
else:
vc = ctx.voice_client
track = await wavelink.YouTubeTrack.search(query)
if track:
await vc.play(track[0])
await ctx.send(f'Now playing: {track[0].title}')
else:
await ctx.send('No track found')
bot.run('YOUR_TOKEN_HERE')
I also tried using FFmpeg to test audio, but the bot still joins and leaves without making any sound. Any ideas on what might be causing this issue?
hey man, had this problem too. check ur audio driver settings on the server. sometimes they mess up n block bot audio. also, make sure ur using the latest wavelink version. older ones can be buggy. if nothing works, try another library like discord-py-voice. good luck!
I’ve dealt with this issue before. One thing to check is your OPUS library. Discord.py relies on OPUS for voice, and sometimes it’s not properly installed or recognized. Try manually installing it with pip install opus-python.
Also, ensure your bot has the ‘Connect’ and ‘Speak’ permissions in the server. Even if it can join, it might not have speaking rights.
Another potential culprit is antivirus software. Some overzealous AVs can interfere with Discord bots’ audio output. Try temporarily disabling your antivirus to see if that’s the problem.
If none of these work, you might want to try a different voice region for your server. Sometimes certain regions can cause issues with bot audio.
I’ve encountered a similar issue with my Discord music bot. It turned out the problem was with my server’s firewall settings. The bot could connect to voice channels, but the audio stream was being blocked.
To troubleshoot, I’d suggest checking your firewall and router settings to ensure they’re not blocking the necessary ports for audio streaming. Usually, UDP ports in the range of 49152-65535 need to be open for Discord voice to work properly.
Also, double-check your wavelink node configuration. Make sure the URI and password are correct, and that the node is actually running and accessible. You might want to add some error handling around the node connection to catch any issues there.
If that doesn’t help, try adding some debug logging in your play function to see if the track is actually being retrieved and if the play method is being called. Sometimes the issue can be with track selection or playback initiation.
Lastly, ensure your bot has the necessary permissions in the Discord server to speak in voice channels. It’s an easy thing to overlook, but it can cause silent joins like you’re experiencing.