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 attributes mute
, muted
, and self_mute
. Perhaps it is possible to modify the voice state of the member with something like member.VoiceState.mute = True
, member.VoiceState.muted = True
or member.VoiceState.self_mute = True
. I'm not sure how to use this method since using the above line of code results in an AttributeError
.discord.Member.edit
(Documentation): member.Member.edit
has the option to set mute
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.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()
discord.VoiceState.self_mute
, you'll see a description of this attribute:Indicates if the user is currently muted by their own accord.
So this means that you cannot set any value, this attribute returns True
/False
depending on user muted his/herself or not.
member.edit
.So I guess you're trying to make 2 methods named set_to_muted
and set_to_unmuted
but for this, you have to edit the main python files of discord.py library. Instead of that, you can create 2 async functions that takes member
as parameter and you can mute them by this way.
async def set_to_muted(member: discord.Member):
await member.edit(mute=True)
async def set_to_unmuted(member: discord.Member):
await member.edit(mute=False)
@client.command()
async def mute(ctx, setting):
voice_channel = discord.utils.get(ctx.guild.channels, name='')
if setting.lower() == 'true':
for member in voice_channel.members:
await set_to_muted(member)
elif setting.lower() == 'false':
for member in voice_channel.members:
await set_to_unmuted(member)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With