Created
October 21, 2023 22:03
-
-
Save Jbziscool/68522bb700c161b2f1d615588f989a81 to your computer and use it in GitHub Desktop.
Report system using discord.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from discord import ui # remember to import this | |
class banreason(ui.Modal, title='Punishment information'): | |
reason = ui.TextInput(label='Reason') | |
def __init__(self, member: discord.Member): | |
super().__init__() | |
self.member = member | |
async def on_submit(self, interaction: discord.Interaction): | |
await self.member.send(f'You have been banned from {interaction.guild}\n**Reason**: {self.reason}') | |
await self.member.ban(reason=f'Report complete - {self.reason}') | |
await interaction.response.send_message(f'Banned user {self.member} for reason {self.reason}', ephemeral=True) | |
await interaction.message.delete() | |
class kickreason(ui.Modal, title='Punishment information'): | |
reason = ui.TextInput(label='Reason') | |
def __init__(self, member: discord.Member): | |
super().__init__() | |
self.member = member | |
async def on_submit(self, interaction: discord.Interaction): | |
await self.member.send(f'You have been kicked from {interaction.guild}\n**Reason**: {self.reason}') | |
await self.member.kick(reason=f'Report complete - {self.reason}') | |
await interaction.response.send_message(f'Kicked user {self.member} for reason {self.reason}', ephemeral=True) | |
await interaction.message.delete() | |
class reportbuttons(discord.ui.View): | |
def __init__(self, member: discord.Member, reporter, reason): | |
super().__init__() | |
self.member = member | |
self.reporter = reporter | |
self.reason = reason | |
@discord.ui.button(label="Ban", style=discord.ButtonStyle.red) | |
async def ban(self, interaction: discord.Interaction, button: discord.ui.Button): | |
await interaction.response.send_modal(banreason(self.member)) | |
@discord.ui.button(label="Kick", style=discord.ButtonStyle.blurple) | |
async def kick(self, interaction: discord.Interaction, button: discord.ui.Button): | |
await interaction.response.send_modal(kickreason(self.member)) | |
@discord.ui.button(label="Dismiss", style=discord.ButtonStyle.green) | |
async def dissmiss(self, interaction: discord.Interaction, button: discord.ui.Button): | |
try: | |
await self.reporter.send(f'Unfortuanately, your report on {self.member} - {self.member.id} was denied') | |
await interaction.response.send_message(f"Dismissed report and notified user", ephemeral=True) | |
except: | |
await interaction.response.send_message(f"Dismissed report, however I failed to notify the user", ephemeral=True) | |
await interaction.message.delete() | |
@bot.command() | |
async def report(ctx, member:discord.Member,*, reason:str): | |
pingrole = 1 # role that gets pinged when there is a new report | |
reportchannelid = 23894732984 # make this something only staff can see | |
embed=discord.Embed(title='**New Report!**', description=f'{ctx.author} has reported {member} - {member.id}\n\n**Report message**: {reason}') | |
embed.set_footer(text='Take action with the buttons below.') | |
await ctx.send(f'<@&{pingrole}>', embed=embed, view=reportbuttons(member, ctx.author, reason)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment