我如何让我的漫游器返回一条消息,指出“权限被拒绝,您没有足够的权限。”

时间:2019-01-28 19:45:01

标签: python discord.py discord.py-rewrite

在这里的代码中,如果执行这些命令之一的用户希望我的机器人在同一频道中发送消息“您没有足够的权限。”

我已经尝试过了,但是没有用。

async def kick(ctx, member: discord.Member):
    if ctx.message.author.server_permissions.kick_members:
        await client.kick
        embed = discord.Embed(title="User Kicked!",
                              description="**{0}** kicked by **{1}**!".format(member, ctx.message.author),
                              color=discord.Colour.green())
        await client.say(embed=embed)
    else:
        embed = discord.Embed(title="Permission Denied.", description="You don't have permission to use this command.",
                              color=discord.Colour.red())
        await client.say(embed=embed)

我在其上添加了else:,但else下方的任何内容均无效。

client = Bot(command_prefix=BOT_PREFIX)
commands = discord.ext.commands

@client.command(name='kick', pass_context=True)
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member):
    if ctx.message.author.server_permissions.kick_members:
        await client.kick
        embed = discord.Embed(title="User Kicked!",
                              description="**{0}** kicked by **{1}**!".format(member, ctx.message.author),
                              color=discord.Colour.green())
        await client.say(embed=embed)```

I expect my bot (client) to say in the same channel the command was sent in to say "You do not have sufficient permissions."


1 个答案:

答案 0 :(得分:0)

您可以使用permissions_for来检查权限而不会引发异常。对于您来说,它看起来像ctx.channel.permissions_for(ctx.author).kick_members

https://discordpy.readthedocs.io/en/rewrite/api.html?highlight=channel#discord.TextChannel.permissions_for

相关问题