在这里的代码中,如果执行这些命令之一的用户希望我的机器人在同一频道中发送消息“您没有足够的权限。”
我已经尝试过了,但是没有用。
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."
答案 0 :(得分:0)
您可以使用permissions_for
来检查权限而不会引发异常。对于您来说,它看起来像ctx.channel.permissions_for(ctx.author).kick_members
。