Python Discord.py命令因on_消息事件而不起作用
我的代码有问题。它不运行任何命令:(事实上,我知道问题出在Python Discord.py命令因on_消息事件而不起作用,python,discord.py,Python,Discord.py,我的代码有问题。它不运行任何命令:(事实上,我知道问题出在on_message部分,但我不知道如何解决它 import discord from discord.ext import commands bot = commands.Bot(command_prefix='//') bdl = open('*Filelocation*', 'r') badwordslist = bdl.read().split() bdl.close() @bot.command() async def
on_message
部分,但我不知道如何解决它
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix='//')
bdl = open('*Filelocation*', 'r')
badwordslist = bdl.read().split()
bdl.close()
@bot.command()
async def hello(context):
print('it works')
context.send('Hello!')
@bot.event
async def on_connect():
print('Connected.')
@bot.event
async def on_ready():
print('READY.')
@bot.event
async def on_message(message):
for badword in message.content.lower().split():
if badword in badwordslist:
await message.channel.send(f'Hey! {message.author.mention} ! Don\'t be rude!')
print(f'{message.author} Said A Bad Word.')
break
else:
return
bot.run("*Token*")
on_message
事件会阻止其他命令。如果要防止出现这种情况,应使用
@bot.event
异步def on_消息(消息):
对于message.content.lower().split()中的坏字:
如果BadWords列表中有BadWords:
等待message.channel.send(f'Hey!{message.author.antify}!不要粗鲁!)
print(f'{message.author}说了一个不好的词')
打破
等待bot.process_命令(消息)
我不明白等待bot后该怎么办。处理命令(消息)?bot。处理命令(消息)
就是你需要做的一切。有了它,你的命令将正常工作。