Discord.py app_commands 同步问题

问题描述 投票:0回答:1
import discord

from discord.ext import commands
from discord import app_commands

intents = discord.Intents.default()
intents.message_content = True

client = commands.Bot(command_prefix='-', intents=intents)


OWNER_ID = 683313053605167185


@client.event
async def on_ready():
    print('ready')
    try:
        guild = discord.Object(id= 1296389488972398644) 
        synced = await client.tree.sync(guild=guild)
        print(f"synced {len(synced)} command(s) to {guild.id}")
    except Exception as e:
        print(f"Error syncing commands: {e}")

@client.tree.command(description="gets the bots ping!")
async def ping(interaction: discord.Interaction):
    embed = discord.Embed(title="Tupiful Utilities Bot ping")
    embed.add_field(name="Bot ping", value=f"{round(client.latency * 1000)}ms")
    await interaction.response.send_message(embed=embed, ephemeral = True)

client.run(# My Token)

我的机器人将 ping 命令同步到测试服务器,但没有将 ping 命令同步到我的主服务器?

我尝试过记录错误(没有显示),搞乱服务器本身,甚至制作了一个全新的机器人,但是出现了同样的问题

python discord.py
1个回答
0
投票

同步命令时,您可以设置

guild
参数,根据 文档,这意味着您专门同步到该公会并且仅同步到该公会。要进行全局同步,就像在所有服务器上同步一样,请将
guild
保留为 None。

await client.tree.sync()
© www.soinside.com 2019 - 2024. All rights reserved.