python - 'Asyncio' 事件循环不起作用 [Discord PY]
问题描述
我已经开始尝试编写一个不和谐的机器人,但是在设置前缀并且事件不起作用时它被缩短了。它只是显示一条错误消息,上面写着“找不到命令“hello””。
import discord
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix="*" ,status=discord.Status.idle, activity=discord.Game("Starting up..."))
@client.event
async def on_ready():
await client.change_presence(status=discord.Status.do_not_disturb, activity=discord.Game("Preparing Puzzle Event"))
print("Bot is running.")
@client.event
async def hello(ctx):
await ctx.send("Hi")
client.run('[The token]')
我知道令牌是有效的,因为我之前没有分配前缀并使用“异步”运行它。
解决方案
@client.event
async def hello(ctx):
await ctx.send("Hi")
这不起作用,因为hello
它不是内置事件。请参阅:https ://discordpy.readthedocs.io/en/latest/api.html#discord-api-events
你想要的可能是一个命令
@client.command()
async def hello(ctx):
await ctx.send("Hi")
这会注册机器人以响应.hello
假设.
是您的前缀的命令
推荐阅读
- c++ - 实现具有未知数量变量的目标
- java - NoSuchMethodError 使用 maven
- html - 垫子滑动切换在垫子工具提示上可见
- spring-boot - Kafka:SubsribableChannels 和 MessageChannels 太多
- python - 如何直接替换列中的 NaN 值?
- c++ - 当我们编写像 void *p 这样的 void 变量时;cout<<&p; cout<
C++输出给出两个不同的地址但是为什么编译器给出两个地址而不是我只写一个变量
void *p ; cout<<&p<
- python - 传递值的形状是 (6, 4),索引意味着 (4, 4)
- node.js - 如何使用 PostgreSQL 查询获取当前月份开始日期和结束日期之间的条目计数
- java - 通过 Jar 运行 Spring Boot 应用程序时 Tomcat 不出现(缺少 ServletWebServerFactory bean)
- r - 将多个栅格的像素值提取到 R 中的相同 csv