Skip to content

Commit

Permalink
Introduce discord slash commands (#165)
Browse files Browse the repository at this point in the history
* Sync command tree on ready

* Make gethubs a slash command

* Switch to discord interactions
  • Loading branch information
axestyra authored Oct 4, 2024
1 parent a55a9f1 commit 884a464
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions server/discordbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ async def announcing(ctx, name=None, description=None, url=None, additional=None
else:
await channel.send(embed=embed)

@self.command()
async def gethubs(ctx):
@self.tree.command()
async def gethubs(interaction: discord.Interaction):
msg = ""
number_players = int(self.server.player_count)
msg += f"**Clients in Areas**\n"
Expand Down Expand Up @@ -114,9 +114,9 @@ async def gethubs(ctx):
if len(msg) > 2000:
msgchunks = [msg[i:i+2000] for i in range(0, len(msg), 2000)]
for chunk in msgchunks:
await ctx.send(chunk)
await interaction.response.send_message(chunk)
else:
await ctx.send(msg)
await interaction.response.send_message(msg)

@self.event
async def on_message(message):
Expand Down Expand Up @@ -169,6 +169,11 @@ async def on_ready(self):
print("Discord Bridge Successfully logged in.")
print("Username -> " + self.user.name)
print("ID -> " + str(self.user.id))
try:
await self.tree.sync()
print("Synced commands!")
except Exception as e:
print(e)
self.guild = self.guilds[0]
self.channel = discord.utils.get(
self.guild.text_channels, name=self.target_channel
Expand Down

0 comments on commit 884a464

Please sign in to comment.