Python Discord机器人正在处理事件,如何修复?

Python Discord机器人正在处理事件,如何修复?,python,discord,discord.py,bots,Python,Discord,Discord.py,Bots,我想我的机器人不工作是因为这两件事 我正在制作一个机器人,如果我键入IP或IP,它会显示服务器地址,如果我键入!!staff它将显示人员列表,但问题是如果我键入ip或ip它将不起作用 import discord import os from discord.ext import commands bot = commands.Bot(command_prefix="!!") client = discord.Client(). @bot.command() async

我想我的机器人不工作是因为这两件事

我正在制作一个机器人,如果我键入
IP
IP
,它会显示服务器地址,如果我键入
!!staff
它将显示人员列表,但问题是如果我键入
ip
ip
它将不起作用

import discord
import os
from discord.ext import commands

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

@bot.command()
async def staff(ctx):
    embed=discord.Embed(title="Mineprison Staff team", description="Dit is het staff team", color=0x39aa31)
    embed.add_field(name="Owners", value="jasper2502, TheArchitectnl", inline=True)
    embed.add_field(name="Manager", value="BastiaanBcraft", inline=False)
    embed.add_field(name="Helpers", value="ItsJeBoyGoogle, Aangepast, MikaySoldier", inline=True)
    embed.set_footer(text="Gemaakt door ItsJeBoyGoogle")
    

    await ctx.send(embed=embed)
    
@bot.listen
async def on_message(message):
    """ some on_message command """
    if message.author.id == bot.user.id:
        return
    msg_content = message.content.lower()
    ip = ['ip', 'IP']

    if any(word in msg_content for word in ip):
        await message.channel.send("Het ip is XXXXXX")        


# EXECUTES THE BOT WITH THE SPECIFIED TOKEN. TOKEN HAS BEEN REMOVED AND USED JUST AS AN EXAMPLE.
bot.run('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
输出:

!!staff
命令起作用,但on_消息中的
给了我以下错误:

Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "ip" is not found and leaving me with no response in the discord channel

使用
IP
而不使用
您必须在消息的
上使用
@bot.event
来运行此代码

但是
bot
已经在\u message
上使用自己的
来运行
命令
,当您在\u message
上创建自己的
时,它将不会运行
命令
。它需要
等待bot.process\u命令(消息)
在自己的
中运行
命令

import os
import discord
from discord.ext import commands

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

@bot.command()
async def staff(ctx):
    embed=discord.Embed(title="Mineprison Staff team", description="Dit is het staff team", color=0x39aa31)
    embed.add_field(name="Owners", value="jasper2502, TheArchitectnl", inline=True)
    embed.add_field(name="Manager", value="BastiaanBcraft", inline=False)
    embed.add_field(name="Helpers", value="ItsJeBoyGoogle, Aangepast, MikaySoldier", inline=True)
    embed.set_footer(text="Gemaakt door ItsJeBoyGoogle")
    await ctx.send(embed=embed)
    
@bot.event
async def on_message(message):
    """ some on_message command """
    
    print('[DEBUG] message:', message)
    
    if message.author.id == bot.user.id:
        return
    
    msg_content = message.content.lower()
    
    if msg_content == 'ip':
        await message.channel.send("Het ip is XXXXXX")        
        return  # skip other commands

    # runs commands like !!staff     
    await bot.process_commands(message)   

TOKEN = os.getenv('DISCORD_TOKEN')
print('TOKEN:', TOKEN)
bot.run(TOKEN)

顺便说一句:

如果使用
Bot
,则不需要
Client
,因为
Bot=Client+commands+other

如果将消息转换为lower,则只能检查
ip
——无需检查
ip

如果您在msg_内容中勾选了
“ip”
,则它可能也会为类似
xxxipxxx
的消息提供答案。也许您应该检查
“ip”==msg\u content
,或者将消息拆分为单词,然后分别检查每个单词。一切都取决于你真正想要得到什么


编辑:

最终,您可以创建正常的
bot.command()
,它与
一起运行!!ip
和信息上的
中添加
(或
bot.command_前缀
)当您收到消息
ip

import discord
import os
from discord.ext import commands

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

@bot.command()
async def staff(ctx):
    embed=discord.Embed(title="Mineprison Staff team", description="Dit is het staff team", color=0x39aa31)
    embed.add_field(name="Owners", value="jasper2502, TheArchitectnl", inline=True)
    embed.add_field(name="Manager", value="BastiaanBcraft", inline=False)
    embed.add_field(name="Helpers", value="ItsJeBoyGoogle, Aangepast, MikaySoldier", inline=True)
    embed.set_footer(text="Gemaakt door ItsJeBoyGoogle")
    await ctx.send(embed=embed)

@bot.command()
async def ip(ctx):
    await ctx.channel.send("Het ip is XXXXXX")        
    
@bot.event
async def on_message(message):
    """ some on_message command """
    
    print('[DEBUG] message:', message)
    
    if message.author.id == bot.user.id:
        return
    
    msg_content = message.content.lower()
    
    if 'ip' == msg_content:
        #message.content = '!!' + msg_content
        message.content = bot.command_prefix + msg_content


    await bot.process_commands(message)   

TOKEN = os.getenv('DISCORD_TOKEN')
print('TOKEN:', TOKEN)
bot.run(TOKEN)

因为没有名为
ip
的命令。您不应该在
on_message
事件中发出“命令”。不应该是
@bot.event
而不是
@bot.listener
?或者甚至没有
@bot.listener
?但如果您更改了\u消息上的
,则可能无法执行
命令
,因为消息上的原始
识别命令并运行指定的功能。而且它需要
super()。在消息(message)
def在消息(message):
如果您的代码可以工作,那么即使在您编写消息
abcIPdef
时,可能也会提供IP。如果你转换了
message.content.lower()
,你应该检查
msg\u content==word
,那么你只能检查
ip
——没有必要检查
ip
,如果你使用
Bot
那么你就不需要
Client
,因为
Bot=Client+command+other
谢谢你在那里帮了我的大忙,非常感谢你!!