曾经浏览过以解决此问题,并实际上尝试将bot.process_commands(message)插入我的代码中,但似乎无济于事。到目前为止,这是代码。只有on_message事件起作用,而命令无效。
import discord
from discord.ext import commands
from discord.ext.commands import CommandNotFound
bot = commands.Bot(command_prefix='/')
@bot.event
async def on_message(message):
if bot.user == message.author:
return
message.content = message.content.lower()
if message.content.startswith('hello') and str(message.channel) != 'images':
await message.channel.send('Hi')
if str(message.channel) == 'images' and message.content != '':
await message.channel.purge(limit=1)
await bot.process_commands(message)
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, CommandNotFound):
return
raise error
@bot.command()
async def Hamdii (ctx, arg):
await ctx.send(arg)
bot.run('token')
答案 0 :(得分:0)
解决此问题的一种方法是检查on_message()事件中的命令,如下所示:
@bot.event
async def on_message(message):
if bot.user == message.author:
return
message.content = message.content.lower()
if message.content.startswith('hello') and str(message.channel) != 'images':
await message.channel.send('Hi')
if str(message.channel) == 'images' and message.content != '':
await message.channel.purge(limit=1)
if message.content.startswith('/hamdii'):
await message.channel.send(message.content[7:])