【发布时间】:2020-12-24 10:23:06
【问题描述】:
我目前正在开发一个不和谐的笑话机器人,但我仍然想要一些功能。我有一些命令,除非我有“on message”事件,否则它们都可以正常工作。 “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”事件没有多大意义,它是我和我的朋友之间的一个内部笑话。
【问题讨论】:
标签: python python-3.x discord discord.py discord.py-rewrite