I am working on a discord bot for my private server that plays an mp3 file when someone joins the afk channel. The afk channel automatically sets the user to muted when joining, this includes the bot. I am having trouble getting the bot to unmute after joining the channel. The bot has admin permissions so it should be able to unmute its self.
@client.event
async def on_voice_state_update(member, before, after):
if before.channel and after.channel:
channel = after.channel
randomSong= random.choice(os.listdir("file"))
if channel.id == #id:
voice = await channel.connect()
source = FFmpegPCMAudio(f"{randomSong}")
voice.play(source )
print(randomSong)
After reading the documentation, connect() can take a self_mute parameter that I set the False but the bot is still muted when it joins the voice channel. I also tried to look up the solution and found this but it didn't really help me.
@client.event
async def on_voice_state_update(member, before, after):
if before.channel and after.channel:
channel = after.channel
randomSong= random.choice(os.listdir("file"))
if channel.id == #id:
voice = await channel.connect(**self_mute=False**)
source = FFmpegPCMAudio(f"{randomSong}")
voice.play(source )
print(randomSong)
I should say from the start this is not the best way, but this is how I did it:
guild = client.get_guild(server_id)
bot_user = guild.get_member(bot_id)
await bot_user.edit(mute=False)
self_mute argument only changes the client sides mute. If you join an afk channel, you are server muted instead. You need to get both the server's and the bot's IDs and put them there. Hope this helps!
EDIT:
Instead of bot_user = guild.get_member(bot_id)
you can use bot_user = guild.me