【发布时间】:2020-06-03 07:42:48
【问题描述】:
问题是主文件和 cog 文件中的所有代码都是正确的,尽管出于某种原因on_message()
不起作用。运行它时我没有遇到任何异常,但它没有做任何不和谐的事情。
这是主要代码,这也会加载齿轮。
import discord
from discord.ext import commands
from discord.utils import get
import os
from dotenv import load_dotenv
load_dotenv('.env')
token = os.getenv('TOKEN')
bot = commands.Bot(command_prefix='$')
client = discord.Client()
@client.event
async def on_ready():
print(' Made by Termed#6382')
print(' Bot events are logged below : ')
print(' ----------')
for file in os.listdir('./cogs'):
if file.endswith('.py') and not file.startswith('_'):
bot.load_extension(f'cogs.{file[:-3]}')
print(' Loaded {}'.format(file))
client.run(token)
bot.run(token)
这是 cog 文件,在 cog 文件夹中
import discord
import os
from discord.ext import commands
from discord.utils import get
import asyncio
client = discord.Client()
class onMessage(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_message(message):
message_content = message.content
if message_content.isupper():
if message.author.id == 'XX':
await message.channel.send('{}No u'.format(message.author.mention))
message_author = message.author
await message.channel.send('{} , Please refrain from using too many capital letters.'.format(message.author.mention))
print(' Warned {} for too many capital letters'.format(message_author))
def setup(bot):
bot.add_cog(onMessage(bot))
【问题讨论】:
标签: python-3.x discord.py