Spaces:
Running
Running
Modify
Browse files- discord_bot.py +13 -9
discord_bot.py
CHANGED
@@ -29,8 +29,8 @@ check_functions = {
|
|
29 |
|
30 |
intents = discord.Intents.default()
|
31 |
intents.message_content = True
|
32 |
-
bot = commands.Bot(command_prefix='>', intents=intents)
|
33 |
-
tree = bot.tree
|
34 |
|
35 |
|
36 |
with open("discord.json", "r") as f:
|
@@ -149,21 +149,25 @@ for command in json_data["command"]:
|
|
149 |
"""
|
150 |
|
151 |
|
152 |
-
class
|
153 |
def __init__(self, *args, **kwargs):
|
154 |
-
|
155 |
self.tree = app_commands.CommandTree(self)
|
|
|
156 |
async def setup_hook(self):
|
157 |
# 在这里你可以注册动态生成的命令
|
158 |
self.tree.add_command(app_commands.Command(name="test", callback=self.test, description="test"))
|
159 |
await self.tree.sync() # 同步命令
|
160 |
-
|
|
|
161 |
print(self)
|
162 |
-
print(
|
163 |
print(x)
|
164 |
print(y)
|
165 |
-
|
166 |
-
|
|
|
|
|
167 |
|
168 |
|
169 |
@bot.command()
|
@@ -173,7 +177,7 @@ async def ping(ctx):
|
|
173 |
|
174 |
@bot.event
|
175 |
async def on_ready():
|
176 |
-
await tree.sync()
|
177 |
await bot.tree.sync()
|
178 |
print('We have logged in as {0.user}'.format(bot))
|
179 |
|
|
|
29 |
|
30 |
intents = discord.Intents.default()
|
31 |
intents.message_content = True
|
32 |
+
#bot = commands.Bot(command_prefix='>', intents=intents)
|
33 |
+
#tree = bot.tree
|
34 |
|
35 |
|
36 |
with open("discord.json", "r") as f:
|
|
|
149 |
"""
|
150 |
|
151 |
|
152 |
+
class MyClient(discord.Client):
|
153 |
def __init__(self, *args, **kwargs):
|
154 |
+
super().__init__(*args, **kwargs)
|
155 |
self.tree = app_commands.CommandTree(self)
|
156 |
+
|
157 |
async def setup_hook(self):
|
158 |
# 在这里你可以注册动态生成的命令
|
159 |
self.tree.add_command(app_commands.Command(name="test", callback=self.test, description="test"))
|
160 |
await self.tree.sync() # 同步命令
|
161 |
+
|
162 |
+
async def test(self, interaction: discord.Interaction, x: str, y: int):
|
163 |
print(self)
|
164 |
+
print(interaction)
|
165 |
print(x)
|
166 |
print(y)
|
167 |
+
await interaction.response.send_message(f"x: {x}, y: {y}")
|
168 |
+
intents = discord.Intents.default()
|
169 |
+
bot = MyClient(intents=intents)
|
170 |
+
|
171 |
|
172 |
|
173 |
@bot.command()
|
|
|
177 |
|
178 |
@bot.event
|
179 |
async def on_ready():
|
180 |
+
#await tree.sync()
|
181 |
await bot.tree.sync()
|
182 |
print('We have logged in as {0.user}'.format(bot))
|
183 |
|