【问题标题】:Why isnt my discord bot answering to my messages?为什么我的不和谐机器人不回复我的消息?
【发布时间】:2022-01-09 20:42:24
【问题描述】:

我制作了这个小不和谐机器人来向朋友展示如何做到这一点,以及我以前是如何做到的。但它不和谐地回答我的消息,我找不到错误。

import discord
import os

client = discord.Client()

@client.event
async def on_ready():
  print('Online as {0.user}'.format(client))

@client.event
async def in_message(message):
  if message.author == client.user:
    return

  if message.content.startswith('Hello'):
    await message.channel.send('Hello! {message.author.mention}')

client.run(os.getenv('TOKEN'))

对不起,如果很明显,我就是看不到。

【问题讨论】:

  • 您是否遇到了 Traceback 错误,或者是在 discord 中未正确设置机器人?
  • 我发现了错误,我写的是in_message而不是on_message。很抱歉打扰你啊。

标签: python discord discord.py


【解决方案1】:
  1. 使用on_message 而不是in_message
  2. 格式化字符串'Hello! {message.author.mention}',如f'Hello! {message.author.mention}'

【讨论】:

    【解决方案2】:

    您可以使用而不是使用on_message 事件

    @client.command()
    async def hello(ctx):
       await ctx.send(f"Hello {ctx.author.mention}")
    

    这就是你在 discord.py 中创建实际命令的方式

    【讨论】:

      猜你喜欢
      • 2021-11-30
      • 1970-01-01
      • 2021-03-05
      • 1970-01-01
      • 2021-09-11
      • 2021-07-01
      • 2022-10-08
      • 2021-07-31
      • 2018-11-19
      相关资源
      最近更新 更多