【问题标题】:Discord bot responding to user with their usernameDiscord bot 使用用户名响应用户
【发布时间】:2021-05-11 05:37:42
【问题描述】:

我的机器人有代码可以让你跟它打招呼。目前,它看起来像这样

if message.content.startswith('$hello'):
   await message.channel.send('Hello (message.author.name)!')

当您键入消息 "$hello" 很明显,它会以 “Hello (message.author.name)!”响应! 我如何让机器人实际上用用户名来响应。我可以使用:

if message.content.startswith('$hello'):
   if message.author.name= myname
      await message.channel.send(myname 'Hello!')

但是我必须为服务器中的每个用户都这样做,这会花费太长时间。还有其他方法吗?谢谢!

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    message.author.name 不应该在引号中。所以你可以这样做:

    if message.content.startswith('$hello'):
       await message.channel.send('Hello ' + message.author.name + '!')
    

    if message.content.startswith('$hello'):
       await message.channel.send(f'Hello {message.author.name}!')
    

    【讨论】:

      猜你喜欢
      • 2020-12-22
      • 2018-02-15
      • 2021-10-05
      • 2021-04-24
      • 1970-01-01
      • 2022-12-09
      • 2021-05-19
      • 2021-09-26
      • 2020-08-25
      相关资源
      最近更新 更多