加载齿轮时为什么显示 0 个命令已同步

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

我试图将齿轮添加到我很长的Python不和谐机器人中,但是当我添加齿轮时,它说0个命令已同步,并且我无法在我的服务器中执行斜杠命令。 我正在尝试实现一个命令,该命令基本上包含我测试所需的所有内容,然后加载该命令。它识别并加载 cog,但似乎没有加载命令,我假设问题出在 cog 中而不是 main.py 中。

主.py

imports

activities = [
    discord.Game(name="help"),
    discord.Game(name="me")
]

intents = discord.Intents.all()
intents.members = True
client = commands.Bot(command_prefix='.', intents=discord.Intents.all())
client.remove_command('help')

rcolor = [
    discord.Colour.blurple()
]

@client.event
async def on_ready():
    for file in os.listdir("cogs"):
        if file.endswith(".py"):
            await client.load_extension(f"cogs.{file[:-3]}")
    print("NOAAHBOT is ready, you can now leave the tab")
    embed = discord.Embed(colour=discord.Colour.blurple())
    channel = client.get_channel(channelidhere)
    embed.add_field(name=f'back online',
                    value='noaahbot has been updated.',
                    inline=False)
    await channel.send(embed=embed)
    try:
        synced = await client.tree.sync()
        print(f"synced {len(synced)} commands")
    except Exception as e:
        print(e)
    while True:
        for activity in activities:
            await client.change_presence(activity=activity)
            await asyncio.sleep(2)

client.run("Token")

齿轮

import discord
from discord import app_commands
from discord.ext import commands

class SayCog(commands.Cog):
    def __init__(self, client):
        self.client = client
    
    @commands.command(name="say", description="What should the bot say")
    @app_commands.describe(thing_to_say = "text")
    async def say(interaction: discord.Interaction, thing_to_say: str | None):
        if not interaction.user.guild_permissions.administrator:
            return await interaction.response.send_message("You require administator permisions to use this command")
        if thing_to_say is None:
            await interaction.response.send_message(f'nothing to be said')
        else:
            await interaction.response.send_message(f'{thing_to_say}')


async def setup(client):
    await client.add_cog(SayCog(client))`
python discord.py
1个回答
0
投票

您正在加载普通命令,而不是斜杠命令。要在齿轮内加载斜杠命令,您必须执行以下操作:

@app_commands.command()

© www.soinside.com 2019 - 2024. All rights reserved.