【问题标题】:How can I send the member name when a user tag someone当用户标记某人时如何发送成员名称
【发布时间】:2021-11-24 15:29:00
【问题描述】:

我正在用 Python 制作一个不和谐的机器人,我想在使用命令 ]kill 时发送一个嵌入。所以当我标记某人并使用该命令时,输出不是成员名字。

我需要将其设为标记用户的名称。

这是我的代码。

killgifs = ['https://c.tenor.com/1dtHuFICZF4AAAAC/kill-smack.gif' , 'https://c.tenor.com/gQAWuiZnbZ4AAAAC/pokemon-anime.gif' , 'https://c.tenor.com/PJbU0yjG3BUAAAAd/anime-girl.gif' , 'https://c.tenor.com/Re9dglY0sCwAAAAC/anime-wasted.gif']


@bot.command(name='kill')
async def kill (ctx,person) :
  author = ctx.author
  embed = discord.Embed (color=discord.Color.red())
  embed.set_author(name=f'{author} kills {person}')
  embed.set_image(url = (random.choice(killgifs)))
  await ctx.send(embed=embed)

【问题讨论】:

    标签: python discord.py mention


    【解决方案1】:

    您可以在此处使用discord.Member,因为您不能在嵌入的标题/作者字段中提及某人。只需将您的代码更改为以下内容:

    killgifs = ['https://c.tenor.com/1dtHuFICZF4AAAAC/kill-smack.gif',
                'https://c.tenor.com/gQAWuiZnbZ4AAAAC/pokemon-anime.gif',
                'https://c.tenor.com/PJbU0yjG3BUAAAAd/anime-girl.gif',
                'https://c.tenor.com/Re9dglY0sCwAAAAC/anime-wasted.gif']
    
    
    @bot.command(name='kill')
    async def kill(ctx, person: discord.Member): # Make the person a discord.Member
        author = ctx.author
        embed = discord.Embed(color=discord.Color.red())
        embed.set_author(name=f'{author} kills {person.display_name}') # Display the name
        embed.set_image(url=(random.choice(killgifs)))
        await ctx.send(embed=embed)
    

    【讨论】:

      猜你喜欢
      • 2021-06-21
      • 2021-12-15
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-19
      • 2020-12-30
      相关资源
      最近更新 更多