Skip to content

Commit b11f0f6

Browse files
committed
feat: add example cog with hybrid and slash command implementations
1 parent 3832fb6 commit b11f0f6

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tux/cogs/utility/example.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import discord
2+
from discord import app_commands
3+
from discord.ext import commands
4+
5+
from tux.bot import Tux
6+
from tux.ui.embeds import EmbedCreator
7+
8+
# This is a example cog file for Tux.
9+
10+
11+
class Example(commands.Cog): # Change the name of the class to match your file name.
12+
def __init__(self, bot: Tux) -> None: # You can define variables here and access them with self.<variable>
13+
self.bot = bot
14+
15+
@commands.hybrid_command( # Lets you use both slash and prefix commands.
16+
name="example", # This is the name of the command for both slash and prefix.
17+
aliases=["test"], # Optional aliases for the command.
18+
)
19+
# @commands.command() # This is a prefix command. Avoid this unless absolutely necessary.
20+
async def example_hybrid_or_prefix(self, ctx: commands.Context[Tux]) -> None:
21+
"""
22+
Example command.
23+
24+
Parameters
25+
----------
26+
ctx : commands.Context[Tux]
27+
The context object for the command.
28+
"""
29+
30+
embed = EmbedCreator.create_embed( # Here you can create an embed using the EmbedCreator class.
31+
bot=self.bot,
32+
embed_type=EmbedCreator.INFO,
33+
user_name=ctx.author.name,
34+
user_display_avatar=ctx.author.display_avatar.url,
35+
title="Example Embed",
36+
description="This is an example embed.",
37+
)
38+
39+
await ctx.send(embed=embed)
40+
41+
@app_commands.command(name="example-app-command") # This is a slash command.
42+
async def example_app_command(self, interaction: discord.Interaction) -> None:
43+
"""
44+
Example slash command.
45+
46+
Parameters
47+
----------
48+
interaction : discord.Interaction
49+
The discord interaction object.
50+
"""
51+
52+
embed = EmbedCreator.create_embed( # Here you can create an embed using the EmbedCreator class.
53+
bot=self.bot,
54+
embed_type=EmbedCreator.INFO,
55+
user_name=interaction.user.name,
56+
user_display_avatar=interaction.user.display_avatar.url,
57+
title="Example Embed",
58+
description="This is an example embed.",
59+
)
60+
61+
await interaction.response.send_message(embed=embed)
62+
63+
64+
async def setup(bot: Tux) -> None:
65+
await bot.add_cog(Example(bot)) # Don't forget to change the name of the class to match your file name here too.

0 commit comments

Comments
 (0)