{Discord.py-rewrite} 当我有一个 "On Message" 事件时,机器人命令不起作用
{Discord.py-rewrite} Bot commands don't work while I have an "On Message" event
我目前正在开发一个笑话 discord 机器人,但我仍然需要一些功能。我有几个命令,除非我有我的“消息”事件,否则它们都可以正常工作。 “on message”事件工作得很好,但命令没有。我做错了什么吗?我很困惑,因为我过去有过“关于消息”的事件和命令,而且它们工作得很好。我的代码如下。
import discord
from discord.ext import commands
TOKEN = 'token'
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
print(f'Logged in as: {bot.user.name}')
print(f'With ID: {bot.user.id}')
@bot.command()
async def ping(ctx):
await ctx.send('Pong! Latency: {0}'.format(round(bot.latency, 1)))
@bot.event
async def on_message(message):
if message.channel.id == 751679038841553008:
if message.author == bot.user:
return
else:
if ''.join(message.content.split()).lower()== "egg":
return
else:
await message.channel.send("{} You fool. You absolute buffoon, it is illegal to say anything other than 'egg' in this server. I hope you feel the shame in side you. Us only saying 'egg' in this channel brings peace to our server, and you thinking your above everyone? above ME? You {}, have messed up. I want you to take a long time to reflect your self.".format(message.author.mention, message.author.mention))
else:
return
bot.run(TOKEN)
因此,总而言之,似乎“关于消息”事件和命令不想同时工作。
编辑
我很清楚我的“On Message”活动没有多大意义,这是我和朋友之间的一个内部笑话。
覆盖 on_message()
提供的默认值会禁止来自 运行 的任何额外命令。要解决此问题,请在 on_message()
活动末尾添加 bot.process_commands(message)
行。
@bot.event
async def on_message(message):
await bot.process_commands(message)
if message.channel.id == 751679038841553008:
if message.author == bot.user:
return
else:
if ''.join(message.content.split()).lower() == "egg":
return
else:
await message.channel.send(
"{} You fool. You absolute buffoon, it is illegal to say anything other than 'egg' in this server. I hope you feel the shame in side you. Us only saying 'egg' in this channel brings peace to our server, and you thinking your above everyone? above ME? You {}, have messed up. I want you to take a long time to reflect your self.".format(
message.author.mention, message.author.mention))
else:
return
我目前正在开发一个笑话 discord 机器人,但我仍然需要一些功能。我有几个命令,除非我有我的“消息”事件,否则它们都可以正常工作。 “on message”事件工作得很好,但命令没有。我做错了什么吗?我很困惑,因为我过去有过“关于消息”的事件和命令,而且它们工作得很好。我的代码如下。
import discord
from discord.ext import commands
TOKEN = 'token'
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
print(f'Logged in as: {bot.user.name}')
print(f'With ID: {bot.user.id}')
@bot.command()
async def ping(ctx):
await ctx.send('Pong! Latency: {0}'.format(round(bot.latency, 1)))
@bot.event
async def on_message(message):
if message.channel.id == 751679038841553008:
if message.author == bot.user:
return
else:
if ''.join(message.content.split()).lower()== "egg":
return
else:
await message.channel.send("{} You fool. You absolute buffoon, it is illegal to say anything other than 'egg' in this server. I hope you feel the shame in side you. Us only saying 'egg' in this channel brings peace to our server, and you thinking your above everyone? above ME? You {}, have messed up. I want you to take a long time to reflect your self.".format(message.author.mention, message.author.mention))
else:
return
bot.run(TOKEN)
因此,总而言之,似乎“关于消息”事件和命令不想同时工作。
编辑
我很清楚我的“On Message”活动没有多大意义,这是我和朋友之间的一个内部笑话。
覆盖 on_message()
提供的默认值会禁止来自 运行 的任何额外命令。要解决此问题,请在 on_message()
活动末尾添加 bot.process_commands(message)
行。
@bot.event
async def on_message(message):
await bot.process_commands(message)
if message.channel.id == 751679038841553008:
if message.author == bot.user:
return
else:
if ''.join(message.content.split()).lower() == "egg":
return
else:
await message.channel.send(
"{} You fool. You absolute buffoon, it is illegal to say anything other than 'egg' in this server. I hope you feel the shame in side you. Us only saying 'egg' in this channel brings peace to our server, and you thinking your above everyone? above ME? You {}, have messed up. I want you to take a long time to reflect your self.".format(
message.author.mention, message.author.mention))
else:
return