From 6dd9005f403371a2cce548060067117ab9f4b5ef Mon Sep 17 00:00:00 2001 From: Jed Hazaymeh Date: Tue, 5 Dec 2023 19:26:24 +0000 Subject: [PATCH] Map interactions import to discord --- src/extensions/hello_world.py | 56 +++++++++++++++++------------------ src/main.py | 12 ++++---- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/extensions/hello_world.py b/src/extensions/hello_world.py index e09d7d4..9747b9d 100644 --- a/src/extensions/hello_world.py +++ b/src/extensions/hello_world.py @@ -1,59 +1,59 @@ """ Example extension with simple commands """ -from interactions import * +import interactions as discord -class HelloWorld(Extension): - @slash_command("hello", description="Say hello!") - async def hello(self, ctx: SlashContext): +class HelloWorld(discord.Extension): + @discord.slash_command("hello", description="Say hello!") + async def hello(self, ctx: discord.SlashContext): """A simple hello world command""" await ctx.send("Hello, world!") - @slash_command( + @discord.slash_command( "base_command", description="A base command, to expand on" ) - async def base_command(self, ctx: SlashContext): + async def base_command(self, ctx: discord.SlashContext): ... @base_command.subcommand( "sub_command", sub_cmd_description="A sub command, to expand on" ) - async def sub_command(self, ctx: SlashContext): + async def sub_command(self, ctx: discord.SlashContext): """A simple sub command""" await ctx.send("Hello, world! This is a sub command") - @slash_command("options", description="A command with options") - @slash_option( + @discord.slash_command("options", description="A command with options") + @discord.slash_option( "option_str", "A string option", - opt_type=OptionType.STRING, + opt_type=discord.OptionType.STRING, required=True, ) - @slash_option( + @discord.slash_option( "option_int", "An integer option", - opt_type=OptionType.INTEGER, + opt_type=discord.OptionType.INTEGER, required=True, ) - @slash_option( + @discord.slash_option( "option_attachment", "An attachment option", - opt_type=OptionType.ATTACHMENT, + opt_type=discord.OptionType.ATTACHMENT, required=True, ) async def options( self, - ctx: SlashContext, + ctx: discord.SlashContext, option_str: str, option_int: int, - option_attachment: Attachment, + option_attachment: discord.Attachment, ): """A command with lots of options""" - embed = Embed( + embed = discord.Embed( "There are a lot of options here", description="Maybe too many", - color=BrandColors.BLURPLE, + color=discord.BrandColors.BLURPLE, ) embed.set_image(url=option_attachment.url) embed.add_field( @@ -68,18 +68,18 @@ async def options( ) await ctx.send(embed=embed) - @slash_command("components", description="A command with components") - async def components(self, ctx: SlashContext): + @discord.slash_command("components", description="A command with components") + async def components(self, ctx: discord.SlashContext): """A command with components""" await ctx.send( "Here are some components", - components=spread_to_rows( - Button( + components=discord.spread_to_rows( + discord.Button( label="Click me!", custom_id="click_me", - style=ButtonStyle.PRIMARY, + style=discord.ButtonStyle.PRIMARY, ), - StringSelectMenu( + discord.StringSelectMenu( "Select me!", "No, select me!", "Select me too!", @@ -91,12 +91,12 @@ async def components(self, ctx: SlashContext): ), ) - @component_callback("click_me") - async def click_me(self, ctx: ComponentContext): + @discord.component_callback("click_me") + async def click_me(self, ctx: discord.ComponentContext): """A callback for the click me button""" await ctx.send("You clicked me!") - @component_callback("select_me") - async def select_me(self, ctx: ComponentContext): + @discord.component_callback("select_me") + async def select_me(self, ctx: discord.ComponentContext): """A callback for the select me menu""" await ctx.send(f"You selected {' '.join(ctx.values)}") diff --git a/src/main.py b/src/main.py index 9e571b8..2a202be 100644 --- a/src/main.py +++ b/src/main.py @@ -3,7 +3,7 @@ """ import sys import glob -from interactions import * +import interactions as discord from loguru import logger from pathlib import Path from config import DEBUG, DEV_GUILD, TOKEN @@ -21,10 +21,10 @@ logger.debug(f"Debug mode is {DEBUG}; You can safely ignore this.") # Initialize the client - client = Client( + client = discord.Client( token=TOKEN, - activity=Activity( - name="Webgroup issues", type=ActivityType.WATCHING + activity=discord.Activity( + name="Webgroup issues", type=discord.ActivityType.WATCHING ), debug_scope=DEV_GUILD, auto_defer=True, @@ -42,12 +42,12 @@ try: client.load_extension(extension) logger.info(f"Loaded extension: {extension}") - except errors.ExtensionLoadException as e: + except discord.errors.ExtensionLoadException as e: logger.exception(f"Failed to load extension: {extension}", exc_info=e) # Start the client - @listen() + @discord.listen() async def on_startup(): logger.info(f"Logged in as {client.user}")