# Code written by Jocadbz(madureirajoaquim95@gmail.com) # Code revised by BodgeMaster # Code Licensed under GPL 3.0 import sys, time, json import discord from discord import app_commands import typing from discord.ext import commands import discord.utils BOOT_TIME = time.time() config_file = open("config.json", "r") config = json.loads(config_file.read()); config_file.close() def seconds_elapsed(): return int(time.time() - BOOT_TIME) class MyClient(discord.Client): def __init__(self, *, intents: discord.Intents): super().__init__(intents=intents) self.tree = app_commands.CommandTree(self) async def setup_hook(self): await self.tree.sync() intents = discord.Intents.default() client = MyClient(intents=intents) bot = commands.Bot(command_prefix='lb!', intents=intents) @client.event async def on_ready(): print(f'Logged in as {client.user} (ID: {client.user.id})') print('------') @client.tree.command(name="change_hostname") @app_commands.describe(distro='Assign yourself a role') async def distro(interaction: discord.Interaction, distro: eval("typing.Literal[\""+ "\", \"".join(config["roles"].keys()) +"\"]")): if not interaction.guild.id==config["guild"]: print("Role assignment attempted from unknown guild.") return user = interaction.user role = discord.utils.get(interaction.guild.roles, id=config["roles"][distro]) try: await user.add_roles(role) await interaction.response.send_message(content=f'Added {role}.') prnt("Added role.") except: await interaction.response.send_message(content='Something went wrong.') print("Failed to add role. Permissions set correctly?") # This context menu command only works on messages @client.tree.context_menu(name='Report to Moderators') async def report_message(interaction: discord.Interaction, message: discord.Message): if not interaction.guild.id==config["guild"]: return await interaction.response.send_message( f'Thanks for reporting.', ephemeral=True ) log_channel = interaction.guild.get_channel(config["report channel"]) 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) @client.tree.command(name="status") async def status(interaction: discord.Interaction): embed = discord.Embed(title='System Stats') embed.description = f"""Uptime: {seconds_elapsed()} System: {sys.platform}""" url_view = discord.ui.View() await interaction.response.send_message(embed=embed, view=url_view) print("Status queried.") client.run(sys.argv[1])