【问题标题】:Discord.py Move Members PermissionDiscord.py 移动成员权限
【发布时间】:2021-07-12 06:03:43
【问题描述】:

我正在制作一个不和谐的机器人,它有一个移动命令,可以将一个语音通道中的所有成员移动到另一个,主要问题是这个命令应该只适用于那些拥有移动成员权限的人,但它不起作用!即使用户拥有该权限,它也不起作用并且它总是向我显示错误。代码如下:

def in_voice_channel():
    def predicate(ctx):
        return ctx.author.voice and ctx.author.voice.channel
    return check(predicate)

@in_voice_channel()
@client.command()
@commands.has_permissions(move_members=True)
async def moveall(ctx, *, channel : discord.VoiceChannel):
    author_ch = ctx.author.voice.channel.mention
    for members in ctx.author.voice.channel.members:
        await members.move_to(channel)
    await ctx.send(f'Moved everyone in {author_ch} to {channel.mention}!')

【问题讨论】:

  • 显示什么错误?
  • 抱歉回复晚了You are missing Move Members permission(s) to run this command.

标签: python discord.py


【解决方案1】:

此代码中的问题不在于权限设置。 @commands.has_permissions(move_members=True) 是要走的路。

@in_voice_channel()装饰器有什么用? 据我所知,这不是来自 discord.py

更新

经过我自己的测试,即使“移动成员”是正确的权限,取决于discord.py docs,但它似乎无法正常工作。

您可以改用 @commands.has_role() 之类的其他检查来完成这项工作,或者等到错误得到修复。

【讨论】:

  • You are missing Move Members permission(s) to run this command. 这是我遇到的错误
  • 我编辑了你可以查看的问题
  • 那我猜这个问题与 Discord 权限有关。
【解决方案2】:

@commands.has_permissions() 检查频道权限,文本频道没有 move_members 或 mute_members 权限。

您要查找的是@commands.has_guild_permissions(),它会检查该用户是否具有服务器范围的移动/静音成员权限。

这意味着要检查用户是否有move_member,您需要将@commands.has_guild_permissions(move_members=True) 放在您的函数/命令之前。

【讨论】:

    猜你喜欢
    • 2021-09-01
    • 2020-12-21
    • 2021-08-12
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 2021-01-30
    • 2021-07-09
    相关资源
    最近更新 更多