【发布时间】:2021-01-21 17:35:44
【问题描述】:
我最近一直在尝试用 python 开发一个不和谐的机器人。我这样做是为了如果一条消息包含某个数字,它会做出反应并发送一条消息。这是cog文件中的代码:
import discord
from discord.ext import commands
nice_numbers = ['69', '420']
class Auto(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_message(self, message):
msg = message.content
if message.author == self.client.user:
return
if any (word in msg for word in nice_numbers):
await message.add_reaction('????')
await message.channel.send(f'lmao nice')
def setup(client):
client.add_cog(Auto(client))
问题是,当用户提及某个频道(在本例中为 #general、#super-private-testing 和 #resources)时,机器人也会以相同的消息和反应进行响应。我似乎无法修复它或弄清楚它为什么会发生。我对python还是很陌生,所以有人可以告诉我我做错了什么吗?
【问题讨论】:
标签: python discord.py discord.py-rewrite