python - discord.py 命令没有响应
问题描述
代码:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
bot = Bot(command_prefix = ".")
@bot.event
async def on_message(message):
print(message.content)
if message.author == bot.user:
return
if message.content.startswith("hello"):
await message.channel.send('hello!')
@bot.command(name="lol")
async def _lol(ctx):
print("lelele")
print(ctx.author)
await ctx.send("lelele")
- 当我输入 .lol 时,Bot 没有响应
- 如果我输入“你好”,机器人会回答
- 问题出在哪里?
解决方案
覆盖提供的默认值会on_message
禁止运行任何额外的命令。要解决此问题,bot.process_commands(message)
请在on_message
.
import discord
from discord.ext.commands import Bot
from discord.ext import commands
bot = Bot(command_prefix=".")
@bot.event
async def on_message(message):
print(message.content)
if message.author == bot.user:
return
if message.content.startswith("hello"):
await message.channel.send('hello!')
await bot.process_commands(message)
@bot.command(name="lol")
async def _lol(ctx):
print("lelele")
print(ctx.author)
await ctx.send("lelele")
推荐阅读
- azure-blob-storage - Azure Blob 存储文件访问
- jquery - 通过选择菜单进行 Swiperjs 分页
- amazon-web-services - 如何检查一个账户的一个 Amazon S3 存储桶中的文件是否与另一个账户的 Amazon S3 存储桶中的文件相同
- c - C通过PID以编程方式将Enter发送到cmd.exe
- python - 由于不可克隆性,将 KerasRegressor 与 cross_validate 一起使用失败
- android - Android:工具栏中的泄漏
- python - 自动从 Strava 的 API 获取授权码
- python - 为 Gmail api 创建电子邮件
- flutter - Firestore Cloud 规则,以便在不共享父/同级文档的情况下将嵌套文档和子内容共享给另一个用户
- excel - EXCEL:检查时间是否在两次之间