joytou commited on
Commit
cef27c1
·
1 Parent(s): dd7f683
Files changed (1) hide show
  1. discord_bot.py +15 -2
discord_bot.py CHANGED
@@ -118,16 +118,18 @@ async def generateStatus(id: str):
118
  return f'Position in queue: {details["queue_position"]}, wait time: {details["wait_time"]}s'
119
 
120
 
121
-
122
  # 根据 json 数据动态创建命令
123
  for command in json_data["command"]:
124
  @tree.command(name=command["name"], description=command["description"])
125
- async def dynamic_command(**kwargs):
126
  print(kwargs)
 
127
  # 动态调用命令对应的函数
128
  function_name = command["function"]
129
  function = globals()[function_name]
130
  result = await function()
 
131
 
132
  # 动态创建参数
133
  #params = [app_commands.Parameter(name=param["name"], display_name=param['name'], description=param["description"], type=TYPE_MAPPING[param["type"]], autocomplete=False, required=True)
@@ -144,7 +146,18 @@ for command in json_data["command"]:
144
 
145
  # 将命令添加到 bot 的 command tree
146
  bot.tree.add_command(tree_command)
 
 
147
 
 
 
 
 
 
 
 
 
 
148
 
149
 
150
  @bot.command()
 
118
  return f'Position in queue: {details["queue_position"]}, wait time: {details["wait_time"]}s'
119
 
120
 
121
+ """
122
  # 根据 json 数据动态创建命令
123
  for command in json_data["command"]:
124
  @tree.command(name=command["name"], description=command["description"])
125
+ async def dynamic_command(interaction: discord.Interaction, **kwargs):
126
  print(kwargs)
127
+ await interaction.response.defer()
128
  # 动态调用命令对应的函数
129
  function_name = command["function"]
130
  function = globals()[function_name]
131
  result = await function()
132
+ await interaction.followup.send(result)
133
 
134
  # 动态创建参数
135
  #params = [app_commands.Parameter(name=param["name"], display_name=param['name'], description=param["description"], type=TYPE_MAPPING[param["type"]], autocomplete=False, required=True)
 
146
 
147
  # 将命令添加到 bot 的 command tree
148
  bot.tree.add_command(tree_command)
149
+ """
150
+
151
 
152
+ class Test:
153
+ def __init__(self, client):
154
+ client.tree.add_command(app_commands.Command(name="test", callback=self.test, description="test"))
155
+ def test(self, inter, x: str, y: int):
156
+ print(self)
157
+ print(inter)
158
+ print(x)
159
+ print(y)
160
+ Test(bot)
161
 
162
 
163
  @bot.command()