首页 > 解决方案 > '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]')

我知道令牌是有效的,因为我之前没有分配前缀并使用“异步”运行它。

标签: pythondiscorddiscord.py

解决方案


@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假设.是您的前缀的命令


推荐阅读