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
谢谢你在那里帮了我的大忙,非常感谢你!!