无法识别与 Python 不一致的命令

时间:2021-07-24 01:14:18

标签: python discord discord.py

我运行它,它会连接,但是在运行时它不会返回任何命令。我已经尝试将其更改为每条消息的上下文返回方法。以前只会出现一条消息,现在使用此方法不会出现一条消息,即使两个命令都相同但略有不同。我的错误是什么?抱歉,这实际上是我第一次尝试使用不和谐机器人。

import os
import discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
botToken = os.getenv("DiscBotToken")

discClient = discord.Client()
bot = commands.Bot(command_prefix = "!")

@discClient.event
async def on_ready():
    print(f"{discClient.user} is now connected.")
    print('Servers connected to:')
    for guild in discClient.guilds:
        print(guild.name)

@bot.command(name = "about")
async def aboutMSG(ctx):
    aboutResp = "msg"
    await ctx.send(aboutResp)


@bot.command(name = "test")
async def testMSG(ctx):
    testResp = "msg"
    await ctx.send(testResp)
        

    

discClient.run(botToken)

1 个答案:

答案 0 :(得分:1)

您朝着正确的方向前进 commands.Bot 同时拥有 eventcommand,无需仅为事件使用客户端。

在您的情况下,您应该使用 discord.Clientcommands.Bot,而不是同时使用 commands.Bot

而且你只运行客户端

import os
import discord
from discord.ext import commands
from dotenv import load_dotenv

load_dotenv()
botToken = os.getenv("DiscBotToken")

bot = commands.Bot(command_prefix = "!")

@bot.event
async def on_ready():
    print(f"{discClient.user} is now connected.")
    print('Servers connected to:')
    for guild in discClient.guilds:
        print(guild.name)

@bot.command(name = "about")
async def aboutMSG(ctx):
    aboutResp = "msg"
    await ctx.send(aboutResp)


@bot.command(name = "test")
async def testMSG(ctx):
    testResp = "msg"
    await ctx.send(testResp)
        

    

bot.run(botToken)
相关问题