从多个文件导入命令不会同步所有命令

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

所以我有一个不和谐的机器人,它被分成多个我导入的Python文件,当我将它们导入main.py时,它总是只同步上次导入的命令,而忽略所有其余的。这些是进口产品。 (我确实拥有所有必需的进口)

@client.event
async def on_ready():
    print("bot is ready, you can now leave the tab")
    embed = discord.Embed(colour=discord.Colour.blue())
    channel = client.get_channel(channel id here)
    embed.add_field(name=f'back online',
                    value='bot 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)

from cogs.admin import * 
from cogs.data import *
from cogs.economy import *
from cogs.fun import *
from cogs.gambling import *
from cogs.help import *
from cogs.inventory import *
from cogs.leveling import *
from cogs.market import *
from cogs.polls import *
from cogs.role_colors import *
from cogs.shop import *
from cogs.warnings import *
from cogs.xp_boosters import *

and here is the example code for one of the cogs--------------------------------------------

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

@client.event
async def on_ready():
    print("CYKLERBOT is ready, you can now leave the tab")
    try:
        synced = await client.tree.sync()
        print(f"synced {len(synced)} commands")
    except Exception as e:
        print(e)

@client.tree.command(name="say", description = "whats should the bot say")
@app_commands.describe(thing_to_say = "text")
async def _8ball(interaction: discord.Interaction, thing_to_say: str):
    if not interaction.user.guild_permissions.administrator:`enter code here`
        return await interaction.response.send_message("You requre administator permisions to use this command")
    await interaction.response.send_message(f'{thing_to_say}')
python discord.py
1个回答
0
投票

这个问题与歧义有关。您可能为所有 Cogs 提供了相同的类名,并且当您使用

import *
时,您将覆盖以前的导入。使用
import *
是一种不好的做法。我建议仅使用
import cogs
并在整个代码中使用
cogs.fun.xxx
来引用它。

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