Python 3.x 为什么我的on#u消息事件不';t工作(discord.py)
我正在制作一个运行良好的discord机器人,但我想开始使用cogs,因为我认为这是一种更好的编写代码的方式,但现在我的on_消息不再有效,它也没有显示任何错误消息。我在整个互联网上搜索了如何修复它,所有的解释都不适用于我,所以我决定在这里询问。这是我的代码:Python 3.x 为什么我的on#u消息事件不';t工作(discord.py),python-3.x,discord.py,Python 3.x,Discord.py,我正在制作一个运行良好的discord机器人,但我想开始使用cogs,因为我认为这是一种更好的编写代码的方式,但现在我的on_消息不再有效,它也没有显示任何错误消息。我在整个互联网上搜索了如何修复它,所有的解释都不适用于我,所以我决定在这里询问。这是我的代码: from discord.ext import commands TOKEN = 'my token' bot = commands.Bot(command_prefix="$") class Interact
from discord.ext import commands
TOKEN = 'my token'
bot = commands.Bot(command_prefix="$")
class Interactions(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message):
msg = message.content
hi = ["hi", "hello", "hi!", "hello!"]
bye = ["bye", "good bye", "bye!", "good bye!"]
# Messages in english
if str(msg).lower() in hi:
await message.channel.send('Hello!')
if str(msg).lower == 'how are you?':
await message.channel.send("I'm fine")
if str(msg).lower == "what's your favorite food?":
await message.channel.send("Sushi with sweet potato!")
if str(msg).lower == "what do you eat?":
await message.channel.send(
"I don't eat, I'm just a simple bot :pensive:")
if str(msg).lower == "are you fine?":
await message.channel.send("Yes, I am")
if str(msg).lower in bye:
await message.channel.send("Good bye!")
def run():
bot.add_cog(Interactions(bot)
bot.run(TOKEN)
if __name__ == "__main__":
run()
导入:
from discord.ext.commands import command, Cog
TOKEN = 'my token'
bot = commands.Bot(command_prefix="$")
class Interactions(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message):
pass
代码的其余部分:
from discord.ext.commands import command, Cog
TOKEN = 'my token'
bot = commands.Bot(command_prefix="$")
class Interactions(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message):
pass
这应该是可行的,如果不只是ping我;)