I am the owner of an Among Us Discord guild with some bots I implemented into it. When we play over on of the voice calls, sometimes people forget to mute themselves so we can hear them which often reveals valuable information.
I am trying to design a set of commands that will allow one person to easily mute everyone the voice channel. They use the command claim "VC Name"
to claim command over the indicated voice channel, then use the command set_mute "true/false"
to either mute or unmute everyone. The first part I have down, but I am struggling with the code of the second part that actually mutes/unmutes the voice channel members.
While reading the documentation for discord.py, I found a few options that might work, but I don't know how to execute any of them.
discord.VoiceState
(Documentation):discord.VoiceState
has attributesmute
,muted
, andself_mute
. Perhaps it is possible to modify the voice state of the member with something likemember.VoiceState.mute = True
,member.VoiceState.muted = True
ormember.VoiceState.self_mute = True
. I'm not sure how to use this method since using the above line of code results in anAttributeError
.discord.Member.edit
(Documentation):member.Member.edit
has the option to setmute
to True. This actually sets the member to a server mute (and I can't seem to undo it), so I would rather avoid this option unless there is a solution through this method.- I could set a unique role that is assigned to all the members in the voice channel and the bot can set the speak permissions on command. This is the method I am using right now but I would like to use an alternative one, if it exists.
This is the code that I have right now. Under the last if/else
statement is where I will put the solution to mute and unmute the members in the call.
async def mute(ctx, setting):
regex, claimed = re.compile(f"_VC: (Lobby [0-9])_"), False
for role in cx.message.author.roles:
if regex.search(role.name):
claimed = True
break
if not claimed:
await ctx.send("You have not claimed any of the game lobbies")
return
voice_channel = discord.utils.get(ctx.guild.channels, name=regex.search(role.name).group(1))
for member in voice_channel.members:
if setting.lower() == 'true':
await member.voice_state.set_to_muted()
elif setting.lower() == 'false':
await member.voice_state.set_to_not_muted()
.edit(mute=True)
and.edit(mute=False)
. – Nick ODell