import os from discord.ext import commands import discord from discord import…
- User
import os from discord.ext import commands import discord from discord import app_commands
json_files_folder = 'comfyUI-workflows'
class Bot(commands.Bot): def init(self): intents = discord.Intents.default() intents.message_content = True super().init(command_prefix='!', intents=intents,proxy="http://127.0.0.1:7890")
async def setup_hook(self): await self.tree.sync(guild=discord.Object(id=1200468352464863382)) print("Synced slash command for {self.user}") await self.setup_commands() async def on_command_error(self , ctx, error): await ctx.reply(error, ephemeral=True) async def setup_commands(self): # 遍历文件夹下的所有文件夹名 folder_names = [f for f in os.listdir(json_files_folder) if os.path.isdir(os.path.join(json_files_folder, f))] for folder_name in folder_names: group = commands.HybridGroup(name=folder_name) # 遍历文件夹中的json文件 json_files = [f for f in os.listdir(os.path.join(json_files_folder, folder_name)) if f.endswith('.json')] for json_file in json_files: command_name = os.path.splitext(json_file)[0] @group.hybrid_command(name=command_name) async def dynamic_command(ctx): # 在这里编写处理命令的逻辑 await ctx.send(f'执行了动态命令: {command_name}') setattr(Bot, command_name, commands.hybrid_command(name=command_name, with_app_command=True, description="testing")(dynamic_command)) # 处理不在文件夹下的json文件 other_json_files = [f for f in os.listdir(json_files_folder) if f.endswith('.json') and not os.path.isdir(os.path.join(json_files_folder, f))] for json_file in other_json_files: command_name = os.path.splitext(json_file)[0] async def dynamic_command( ctx: commands.Context) -> None: await ctx.defer(ephemeral=True) await ctx.reply("hi") setattr(Bot, command_name, commands.hybrid_command(name=command_name, with_app_command=True, description="testing")(dynamic_command))bot = Bot()
@bot.hybrid_command(name="test", with_app)
@bot.hybrid_command(name="test", with_app_command=True, description="testing")
@app_commands.guilds(discord.Object(id=1200468352464863382))
async def test( ctx: commands.Context) -> None:
await ctx.defer(ephemeral=True)
await ctx.reply("hi")
bot.run('MTIwMDQ1Njk0MTI2OTQyNjE4Nw.GpkQ4X.m_ga-5IVgwVSNE4crl7H-lTITLsS0V1-v5yi3w') 我想动态生成 hybrid_command 这段代码有什么问题,有的话修复它
- Assistant
- User
unsupported type annotation <class 'main.Bot'>\
- Assistant
- User
new_command = commands.hybrid_command(name=command_name, with_app_command=True, description="testing")(dynamic_command). this line report above errs, fix it
- Assistant
- User
Create a new command with the command_name and add it to the bot
new_command = commands.hybrid_command(name=command_name, with_app_command=True, description=“testing”)(dynamic_command). this code report error ,not you changed one - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.