geirawsm / sausage_bot

Another Discord-bot
1 stars 0 forks source link

Add possibility to report messages to mods #54

Open geirawsm opened 10 months ago

geirawsm commented 10 months ago

Shamelessly stolen from this link: https://replit.com/@UMARismyname/Discordpy-slash-commands#main.py


@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(
        0)  # 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)```