@client.command() # or bot.command(), or whatever you're using
async def insult(ctx, member:discord.Member=None):
if member == None: # Happens if ctx.author does not mention a member..
member = ctx.author # ..so by default the member will be ctx.author
# You can use member.mention to mention/ ping/ @ the person assigned as member
await ctx.send(f"Be insulted {member.mention}!")
# A not as good way to do it would be:
await ctx.send(f"Be insulted <@{member.id}>!")
# both methods work the same way, but member.mention is recommended
要在命令中提及用户,可以使用} 对象的更多信息。有关如何在命令中使用此选项的示例也可以在文档中找到,请查看:^{}
member: discord.Member
。这有助于在命令本身中获取成员对象。您可以在此处查看有关如何使用^{您可以在下面查看如何合并这些变量,包括} 未提及成员时控制台中出现错误
None
变量作为默认值,以避免在^{相关问题 更多 >
编程相关推荐