【发布时间】:2022-11-18 23:37:05
【问题描述】:
我使用 python 为我的 discord 机器人创建了一个简单的斜杠命令,以显示机器人延迟。但是,它似乎没有用。你能帮我吗?非常感谢:D。
我的代码:
import time
import discord
from discord import app_commands
from discord.ext import commands
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
prefix = "-"
bot = commands.Bot(command_prefix=prefix,intents=intents)
@client.event
async def on_ready():
await tree.sync(guild=discord.Object(id=ID))
print("Ready!")
@tree.command(name = "ping", description = "test command", guild=discord.Object(id=ID))
async def ping(Interaction):
before = time.monotonic()
message = await Interaction.response.send_message("pong")
ping = (time.monotonic() - before) * 1000
await message.edit(content=f"pong `{int(ping)}ms`") <-- here's the line that's causing the problem..
client.run('TOKEN')
我一直试图在互联网上找到这个问题,但一直找不到。丁: 我试图以某种方式自己修复它,但我是使用 python 编码的新手,但没有成功。
【问题讨论】:
-
不要自动同步,也不要在 on_ready 中调用 API。为什么你有一个你没有使用的
Client和Bot?你遇到了什么错误?
标签: python discord discord.py