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

2024-09-27 21:29:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我是编程初学者,最近才开始使用python。我正试图在一个名为replit的IDE中创建一个discord bot。Replit似乎没有检测到错误,因为它允许我在运行代码时不加下划线或指出任何行。但是,当我运行bot并在discord中键入命令时,bot没有响应。当我返回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'))

Tags: import命令clientmessageisosresponsebot
1条回答
网友
1楼 · 发布于 2024-09-27 21:29:58

每当编写自己的^{} event reference(覆盖默认的discord.pyon_message())时,都需要调用^{} 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)

相关问题 更多 >

    热门问题