【发布时间】:2019-06-21 21:08:48
【问题描述】:
在我的代码中,如果用户执行这些命令之一,我希望我的机器人在同一频道中发送消息“您没有足够的权限。”
我已经尝试过了,但它不起作用。
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."
【问题讨论】:
-
如果检查失败,您需要使用错误处理程序来执行操作。看到这个答案:stackoverflow.com/a/51246799/6779307
-
感谢@PatrickHaugh,救命稻草。像魅力一样工作。
标签: python discord.py discord.py-rewrite