【问题标题】:How do I make my discord bot respond when a specific user sends a message in the channel?当特定用户在频道中发送消息时,如何让我的不和谐机器人做出响应?
【发布时间】:2021-05-07 00:33:38
【问题描述】:

我想让我的不和谐机器人在每次特定用户在聊天中发送消息时做出响应。代码运行,但当该用户发送消息时没有任何反应。

这是我迄今为止尝试过的:

@client.event
async def on_message(message):
    if message.author == client.user:
        return
        
    if message.author.id == '546474118711869440':
        await message.channel.send('shhhhh')

【问题讨论】:

标签: python discord.py bots


【解决方案1】:

它在一个字符串中。您必须将用户 ID 设为 int,因此不要使用引号。

if message.author.id == 546474118711869440:
    await message.channel.send('shhhhh')

【讨论】:

  • 谢谢!我对一个愚蠢的问题不好,哈哈
  • @TyStrong 没关系,发生在我们最好的人身上
猜你喜欢
  • 2021-01-04
  • 2021-06-22
  • 2019-07-11
  • 2021-06-17
  • 2021-08-14
  • 1970-01-01
  • 2020-12-18
  • 2021-05-22
  • 2023-03-16
相关资源
最近更新 更多