【发布时间】:2019-02-15 23:36:12
【问题描述】:
当禁止 Discord 房间的成员时,我想在 +kick 命令中添加可选的 reason 消息。我尝试的代码如下。
命令和示例用法:
+kick <username> <reason>
+kick @Pine#1337 Spamming Messages in Wrong Channel.
代码:
@bot.command(pass_context=True)
async def kick(ctx, user: discord.Member, *, arg, reason):
author = ctx.message.author
data = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
embed = discord.Embed(name="MEMBER_KICKED", description="------------------------------------------------------", color=0x00ff00)
embed.set_author(name="MEMBER_KICKED:\nMember Kicked Successfully")
embed.add_field(name="Kicked by: ", value="{}".format(author.mention), inline=False)
embed.add_field(name="Kicked: ", value="<@{}>".format(user.id), inline=False)
embed.add_field(name="Reason: ", value="{}\n------------------------------------------------------".format(arg), inline=False)
embed.set_footer(text="Requested by {} \a {}".format(author, data), icon_url=author.avatar_url)
await bot.say(embed=embed)
channel = discord.utils.get(user.server.channels, name="logs")
embed = discord.Embed(name="MEMBER_KICKED", description="------------------------------------------------------", color=0xff0000)
embed.set_author(name="MEMBER_KICKED:\nMember Kicked")
embed.add_field(name="Kicked by: ", value="{}".format(author.mention), inline=False)
embed.add_field(name="Kicked: ", value="<@{}>".format(user.id), inline=False)
embed.add_field(name="Reason: ", value="{}\n------------------------------------------------------".format(arg), inline=False)
embed.set_footer(text="Kicked at {}".format(data))
await bot.send_message(channel, embed=embed)
if user.bot == False:
embed = discord.Embed(name="KICKED", description="------------------------------------------------------", color=0xff0000)
embed.set_author(name="KICKED:\nYou've been Kicked")
embed.add_field(name="Kicked by: ", value="{}".format(author.mention), inline=False)
embed.add_field(name="Kicked in: ", value="{}".format(user.server), inline=False)
embed.add_field(name="Reason: ", value="{}\n------------------------------------------------------".format(arg), inline=False)
embed.set_footer(text="Kicked at {}".format(data))
await bot.send_message(user, embed=embed)
if user.bot == True:
pass
reason = arg
await bot.kick(user, reason=reason)
错误:
TypeError: kick() missing 1 required 1 keyword-only argument 'reason'
【问题讨论】:
-
你想对 kick 消息进行什么处理?这是重写分支支持的东西,但异步分支不支持。见
Guild.kick -
当有人键入命令时,例如
+ban <user> <reason>,它禁止一个成员及其arg的原因 -
已编辑:修复标题语法,提供背景信息,修复代码块
标签: python discord.py