diff --git a/bot.py b/bot.py index 797bffe..2f5ebc8 100644 --- a/bot.py +++ b/bot.py @@ -274,7 +274,7 @@ intents.message_content = True # Allow to read message content from arbitrary me # Setup our client client = HeidiClient(intents=intents) -# ------------------------------------------------------------------------------------------------ +# Events ----------------------------------------------------------------------------------------- # NOTE: I defined the events outside of the Client class, don't know if I like it or not... @client.event @@ -301,6 +301,43 @@ async def on_message(message): await client.matchers[matcher](message) break +# Commands --------------------------------------------------------------------------------------- + +# Example +@client.tree.command() +async def hello(interaction: discord.Interaction): + """Says hello!""" + await interaction.response.send_message(f'Hi, {interaction.user.mention}') + +# Example +@client.tree.context_menu(name='Show Join Date') +async def show_join_date(interaction: discord.Interaction, member: discord.Member): + # The format_dt function formats the date time into a human readable representation in the official client + await interaction.response.send_message(f'{member} joined at {discord.utils.format_dt(member.joined_at)}') + +# Example +@client.tree.context_menu(name='Report to Moderators') +async def report_message(interaction: discord.Interaction, message: discord.Message): + # We're sending this response message with ephemeral=True, so only the command executor can see it + await interaction.response.send_message( + f'Thanks for reporting this message by {message.author.mention} to our moderators.', ephemeral=True + ) + + # Handle report by sending it into a log channel + log_channel = interaction.guild.get_channel(821511861178204164) # replace with your channel id + + embed = discord.Embed(title='Reported Message') + if message.content: + embed.description = message.content + + embed.set_author(name=message.author.display_name, icon_url=message.author.display_avatar.url) + embed.timestamp = message.created_at + + url_view = discord.ui.View() + url_view.add_item(discord.ui.Button(label='Go to Message', style=discord.ButtonStyle.url, url=message.jump_url)) + + await log_channel.send(embed=embed, view=url_view) + # ------------------------------------------------------------------------------------------------ # Used to start the bot locally, for docker the variables have to be set when the container is run