我正在尝试编写一个使作者语音通道中的每个成员静音的命令。我这样做是为了让我和我的朋友在我们自动切换到游戏中的语音聊天时可以使自己静音。但是出于我无法解释的原因,我永远无法使它起作用。这是我的代码:
@commands.command()
@commands.has_permissions(mute_members=True)
async def mute(self, ctx):
if ctx.author.voice and ctx.author.voice.channel:
channel = ctx.author.voice.channel
for member in channel.members:
await member.edit(mute=True)
else:
await ctx.send("You are not connected to a voice channel!")
我了解到该漫游器和作者都需要一个静音成员权限,但他们俩都需要!我什至确保它们在角色列表的顶部,并且我编辑了语音通道权限,以允许作者和漫游器的静音成员。无论我做什么,我总是会收到相同的错误!任何帮助将不胜感激!
答案 0 :(得分:0)
async def has_channel_permissions(**kwargs):
def predicate(ctx):
if ctx.author.voice is not None:
if ctx.author.voice.channel is not None:
if kwargs in dict(ctx.author.voice.channel.permissions_for(ctx.author)) and kwargs in dict(commands.user:
return True
else:
return False
await ctx.send("You are not connected to a voice channel!")
return False
return commands.check(predicate)
@commands.command()
@has_channel_permissions(mute_members=True)
async def mute(self, ctx):
channel = ctx.author.voice.channel
for member in channel.members:
await member.edit(mute=True)