Pythion Discord机器人人

2024-06-08 01:05:42 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行像/insult @name这样的命令时,我需要bot@在命令的参数中是person并发送一个图像。剩下的大部分我都能做,但我似乎想不出有什么办法让这个人去做


Tags: name图像命令参数botpersoninsult办法
1条回答
网友
1楼 · 发布于 2024-06-08 01:05:42

要在命令中提及用户,可以使用member: discord.Member。这有助于在命令本身中获取成员对象。您可以在此处查看有关如何使用^{}对象的更多信息。有关如何在命令中使用此选项的示例也可以在文档中找到,请查看:^{}

您可以在下面查看如何合并这些变量,包括None变量作为默认值,以避免在^{}未提及成员时控制台中出现错误

@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

Above code working

相关问题 更多 >

    热门问题