Skip to content

Commit

Permalink
Map interactions import to discord
Browse files Browse the repository at this point in the history
  • Loading branch information
JedHazaymeh committed Dec 5, 2023
1 parent b08d9a6 commit 6dd9005
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
56 changes: 28 additions & 28 deletions src/extensions/hello_world.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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!",
Expand All @@ -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)}")
12 changes: 6 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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}")

Expand Down

0 comments on commit 6dd9005

Please sign in to comment.