英文:
Get bot to unmute self when joining an afk channel
问题
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 itself.
@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 to 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 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)
答案1
得分: 1
我应该从一开始就说,这不是最佳方法,但这是我做的方式:
guild = client.get_guild(server_id)
bot_user = guild.me
await bot_user.edit(mute=False)
self_mute 参数只会改变客户端静音。如果你加入一个AFK频道,你将被服务器静音。你需要获取服务器和机器人的ID,并将它们放在这里。希望这有所帮助!
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论