【问题标题】:Can't get discord bot to mention author (python)无法让不和谐机器人提及作者(python)
【发布时间】:2022-01-10 23:33:56
【问题描述】:
@client.event
async def on_message(message):
  if message.author == client.user:
      return

  if message.content.startswith('!play'):
      await message.channel.send('{author.mention} wants to play a game, would you like to play? @here')

我是新手,所以请解释我做错了什么。

【问题讨论】:

  • 您在 f 字符串中缺少 f"{author.mention}..."
  • 我假设您使用的是 discord.py,所以我为您添加了 discord.py 标签。如果不正确,您可以edit。顺便说一句,欢迎来到 SO!查看tourHow to Ask

标签: python discord discord.py


【解决方案1】:

试试看:

  if message.content.startswith('!play'):
      await message.channel.send(f'{message.author.mention} wants to play a game, would you like to play? @here')

【讨论】:

    【解决方案2】:
    @client.command()
    async def play(ctx):
        author=ctx.author
        await ctx.send(f'Hey @here! {author.mention} wants to play a game! would you like to join them?')
    

    我假设您希望这是一个命令,因此它将检查调用函数的前缀,而不是在 on_message 事件中使用 if 语句。

    【讨论】:

      猜你喜欢
      • 2020-05-18
      • 2018-08-21
      • 2019-02-02
      • 2020-11-08
      • 2020-12-30
      • 2023-04-04
      • 2019-04-09
      • 2020-11-18
      • 1970-01-01
      相关资源
      最近更新 更多