我的不和谐机器人没有响应 replit (Python) 中的任何命令

时间:2021-05-30 17:28:29

标签: python discord chatbot

我是编程初学者,最近才开始使用 Python。我正在尝试在名为 replit 的 IDE 中创建一个不和谐的机器人。 Replit 似乎没有检测到错误,因为它让我可以在不加下划线或指出任何行的情况下运行代码。但是,当我运行机器人并在 discord 中键入命令时,机器人没有响应。当我回到 replit 时,它仍然没有检测到任何错误或在控制台中指出任何内容。我尝试以两种不同的格式制作机器人命令。第一个(用户打招呼,机器人响应)有效,但之后的其他两个命令有多个响应,机器人应该从该列表中选择一个随机响应。这两个命令不起作用。代码如下:

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

  if message.content.startswith ('^hello'):
   await message.channel.send('Hello...( ・_・)ノ')

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

import os
import random
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
#help commands
bot = commands.Bot(command_prefix='^')
@bot.command(name='help')
async def help(ctx):
    omori_responses = [
        'OMORI’s main command categories are: FUN, CURRENCY, OMORI, SUNNY, BASIL, MARI, HERO, KEL, AUBREY, WHITESPACE, DREAMWORLD, and BLACKSPACE. Please use the command omo help <insert command category>',
        
            'OMORI’s main command categories are: FUN, CURRENCY, OMORI, SUNNY, BASIL, MARI, HERO, KEL, AUBREY, WHITESPACE, DREAMWORLD, and BLACKSPACE. Please use the command omo help <insert command category>' 
          ]
    response = random.choice(omori_responses)
    await ctx.send(response)
client.run(os.getenv('TOKEN'))
#whitespace commands
bot = commands.Bot(command_prefix='^')
@bot.command(name='ws')
async def white_space(ctx):
    omori_responses = [
        'Whitespace. A single black lightbulb hangs from the ceiling above...wherever above is',
        'Whitespace. You have been here since as far back as you can remember...whenever that is. Everything is bright white. There are no walls. There is a floor...it is always cold.',
        
            'Whitespace. Everything you need is here. A laptop, sketchbook, tissue box, blanket, and MEWO, your cat.',
            'Whitespace. There is a door here. Beyond this door is a colorful world, unlike here...' 
          ]
    response = random.choice(omori_responses)
    await ctx.send(response)
client.run(os.getenv('TOKEN'))

1 个答案:

答案 0 :(得分:0)

每当您编写自己的 on_message() event reference(覆盖默认的 discord.py on_message())时,您都需要调用 Bot.process_commands() method

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return

    if message.content.startswith ('^hello'):
       await message.channel.send('Hello...( ・_・)ノ')

    await bot.process_commands(message)