menu

Questions & Answers

Discord Bot joins voice channel muted

I am trying to make my discord bot play an MP3 file in a voice channel, however, upon joining the discord bot remains muted, and therefore the audio file isn't audible, even if it may be playing. Here is my code:

@client.event
  async def on_ready():
    print(f'{client.user} is now running')
    channel = discord.utils.get(client.get_all_channels(), id=<vc id>)
    voice = await channel.connect()
    source = FFmpegPCMAudio('<filename>.mp3') 
    player = voice.play(source)

Does anyone know how to unmute the discord bot? I'm confident that I've had set the bot permission to be able to speak in voice chats before I invited it to my discord server.

Comments:
2023-01-20 00:30:14
I don't think await can be used on its own like that. You have to await something. You can't just generally wait for the sake of waiting. This code will not parse, let alone run.
2023-01-20 00:30:14
That was an error, pls ignore that
Answers(1) :

First, voice.play is not async. You shouldn't have await for voice.play
Second, don't do so many things in on_ready event. Do these by commands (you need to change discord.Client to commands.Bot. See this
Third, if you run this locally, you need to have executable specified in your FFmpegPCMAudio(executable=..., source=...). See this. Also, you need to install ffmpeg first in order to specify the path.
Fourth, Check your intents, make sure you have intents.voice_states enabled. If you already set Intents.default or Intents.all then you already have the voice_states.

Comments:
2023-01-20 00:30:14
Im on linux, and I have ffmpeg installed. I need the bot to join vc on startup for this specific purpose anyway