[英]discord.py not responding to any commands
我按照教程将基本音乐 function 添加到 discord 机器人,但它不响应任何命令。 我收到“henlo frens i is alieving”消息,表明机器人已准备好,并且没有出现错误。 但是当我尝试使用 ping 命令时,我没有得到任何响应,并且与我编写的其他机器人不同,终端中没有任何显示。
from plznodie import plznodie
from discord.ext import commands
import music
import time
#vars
cogs=[music]
intents = discord.Intents()
intents.all()
client = commands.Bot(command_prefix = "!" , intents=intents)
intents.members = True
activvv = discord.Game("you guys complain")
#config
for i in range(len(cogs)):
cogs[i].setup(client)
@client.event
async def on_ready ():
await client.change_presence(status = discord.Status.online, activity = activvv)
print("Henlo frens i is alieving")
@client.command()
async def ping(ctx):
before = time.monotonic()
message = await ctx.send("Pong!")
ping = (time.monotonic() - before) * 1000
await message.edit(content=f"Pong! `{int(ping)}ms`")
client.run("TOKEN")```
不要在您的机器人或客户端中的change_presence
中on_ready
_presence(或进行 API 调用)。 Discord 很有可能在 READY 或 GUILD_CREATE 事件(1006 关闭代码)期间完全断开您的连接,您无法阻止它。
而是在这些类的构造函数中设置activity
和status
kwargs。
bot = commands.Bot(command_prefix="!", activity=..., status=...)
如文档中所述, on_ready
也被多次触发,而不仅仅是一次。
要处理您需要添加 on_message function 的命令
@client.event
async def on_message(msg):
await client.process_commands(msg)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.