python - discord.py @bot.command() 没有运行
问题描述
我有这样的东西。
from flask import Flask
from threading import Thread
import discord
from discord.ext import commands, tasks
from discord.utils import get
import requests
from Moderator.badwords import words
import time
import datetime
from Stats.uptime import data
help_command = commands.DefaultHelpCommand(
no_category = 'Commands'
)
intents = discord.Intents().all()
bot = commands.Bot(command_prefix='!', description="Hey there, I'm Botty (for example)!", help_command=help_command, intents=intents)
@bot.command()
async def hello(ctx):
await ctx.send(ctx.author.mention + " hello!")
@bot.event
async def on_ready():
print('Ready!')
@bot.event
async def on_message(message):
for word in words:
if word in message.content.lower():
await message.delete()
await message.channel.send("Oops! Seems like " + message.author.mention + " was trying to send a message that was breaking the " + bot.get_channel(783064049859559434).mention + ". Luckily, I deleted it before it caused any more damage. Don't send any more messages like that!\n\nIf you think that I made an error, please report it in " + bot.get_channel(783074030265040916).mention + ", " + bot.get_channel(783074002255478848).mention + " or in " + bot.get_channel(783092164590174251).mention)
@bot.event
async def on_member_join(member):
print(f"{member} joined the server")
bot.run(TOKEN)
现在,我可以毫无错误地编译和运行此代码,并且当成员加入或用户发送消息时,一切正常。但是当涉及到运行命令时,它甚至没有启动。有什么我想念的吗?
提前致谢
解决方案
覆盖默认提供的 on_message 会禁止运行任何额外的命令。要解决此问题,
bot.process_commands(message)
请在 on_message 末尾添加一行。
如果覆盖on_message
,则需要使用await bot.process_commands(message)
以便处理命令。尝试将其添加到您的on_message
活动中。
推荐阅读
- php - transform() 必须是 App\DigitalCase 的一个实例
- sql - 在托管服务上运行作业的 SQL Server 代理的替代方案
- c - libsodium ed25519 密钥生成器打印
- excel - 在框架内选择选项值
- javascript - Nodejs Jasmine:模拟 Promise 函数以免碰到真正的代码是给 DEFAULT_TIMEOUT_INTERVAL
- ffmpeg - ffmpeg : 转换为与三星蓝光兼容的 mkv
- vue.js - 不使用 npm 或 webpack 时未应用 Vuetify 主题
- c# - 加密方法在一台 PC 上失败,但在其他 PC 上有效
- visual-studio-code - VS Code fallback DOM 集成终端忽略光标样式设置
- javascript - 自动化 buttonclick 苹果脚本时的“缺失值”结果