freddyaboulton commited on
Commit
8bf0102
·
1 Parent(s): 126a245

Deploy Discord Bot

Browse files
Files changed (1) hide show
  1. app.py +7 -18
app.py CHANGED
@@ -43,11 +43,7 @@ class MyClient(discord.Client):
43
  super().__init__(intents=intents)
44
  self.tree = discord.app_commands.CommandTree(self)
45
 
46
- # In this basic example, we just synchronize the app commands to one guild.
47
- # Instead of specifying a guild to every command, we copy over our global commands instead.
48
- # By doing so, we don't have to wait up to an hour until they are shown to the end-user.
49
  async def setup_hook(self):
50
- # This copies the global commands over to your guild.
51
  synced = await self.tree.sync()
52
  print(f"Synced commands: {', '.join([s.name for s in synced])}.")
53
 
@@ -76,21 +72,14 @@ thread_to_user = {}
76
 
77
 
78
  @bot.tree.command(
79
- name="chat",
80
- description="Enter some text to chat with the bot! Like this: /chat Hello, how are you?",
81
  )
82
  async def chat(interaction: discord.Interaction, prompt: str):
83
- if ctx.author.id == bot.user.id:
84
  return
85
  try:
86
  message = await interaction.channel.send("Creating thread...")
87
-
88
- # # User triggered bot via !chat
89
- # if ctx.message.content:
90
- # prompt = ctx.message.content.replace(
91
- # f"{bot.command_prefix}chat", ""
92
- # ).strip()
93
-
94
  thread = await message.create_thread(name=prompt)
95
  loop = asyncio.get_running_loop()
96
  client = await loop.run_in_executor(None, get_client, None)
@@ -195,15 +184,15 @@ else:
195
 
196
  ## How to use it?
197
 
198
- The bot can be triggered via `!chat` followed by your text prompt.
199
 
200
  ## Enabling slash commands
201
 
202
  If you are the owner of this bot, call the `!sync` command from your discord server.
203
- This will allow anyone in your server to call the bot via `/chat`.
204
- This is known as a slash command and is a nicer experience than calling the bot via `!chat`.
205
 
206
- After calling `!sync`, it may take a few minutes for `/chat` to be recognized as a valid command
207
  in your server.
208
 
209
  ⚠️ Note ⚠️: It is best to create a separate bot per command if you intend to use slash commands. Also make sure
 
43
  super().__init__(intents=intents)
44
  self.tree = discord.app_commands.CommandTree(self)
45
 
 
 
 
46
  async def setup_hook(self):
 
47
  synced = await self.tree.sync()
48
  print(f"Synced commands: {', '.join([s.name for s in synced])}.")
49
 
 
72
 
73
 
74
  @bot.tree.command(
75
+ name="echo",
76
+ description="Enter some text to chat with the bot! Like this: /echo Hello, how are you?",
77
  )
78
  async def chat(interaction: discord.Interaction, prompt: str):
79
+ if interaction.author.id == bot.user.id:
80
  return
81
  try:
82
  message = await interaction.channel.send("Creating thread...")
 
 
 
 
 
 
 
83
  thread = await message.create_thread(name=prompt)
84
  loop = asyncio.get_running_loop()
85
  client = await loop.run_in_executor(None, get_client, None)
 
184
 
185
  ## How to use it?
186
 
187
+ The bot can be triggered via `!echo` followed by your text prompt.
188
 
189
  ## Enabling slash commands
190
 
191
  If you are the owner of this bot, call the `!sync` command from your discord server.
192
+ This will allow anyone in your server to call the bot via `/echo`.
193
+ This is known as a slash command and is a nicer experience than calling the bot via `!echo`.
194
 
195
+ After calling `!sync`, it may take a few minutes for `/echo` to be recognized as a valid command
196
  in your server.
197
 
198
  ⚠️ Note ⚠️: It is best to create a separate bot per command if you intend to use slash commands. Also make sure