-
Notifications
You must be signed in to change notification settings - Fork 36
/
slashcommands_transformers.py
45 lines (29 loc) · 1.36 KB
/
slashcommands_transformers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import typing
import settings
import discord
from discord.ext import commands
from discord import app_commands
logger = settings.logging.getLogger("bot")
class SlapReason(typing.NamedTuple):
reason : str
class SlapTransformer(app_commands.Transformer):
async def transform(self, interaction: discord.Interaction, value: str) -> SlapReason:
return SlapReason(reason=f"*** {value} *** ")
def run():
intents = discord.Intents.all()
bot = commands.Bot(command_prefix="!",intents=intents)
@bot.event
async def on_ready():
logger.info(f"User: {bot.user} (ID: {bot.user.id})")
await bot.load_extension("slashcmds.welcome")
bot.tree.copy_global_to(guild=settings.GUILDS_ID)
await bot.tree.sync(guild=settings.GUILDS_ID)
@bot.tree.command()
async def slap(interaction: discord.Interaction, reason: app_commands.Transform[SlapReason, SlapTransformer]):
await interaction.response.send_message(f"Ouch {reason}", ephemeral=True)
@bot.tree.command()
async def range(interaction: discord.Interaction, value: app_commands.Range[int, None, 10]):
await interaction.response.send_message(f"Range Result {value}", ephemeral=True)
bot.run(settings.DISCORD_API_SECRET, root_logger=True)
if __name__ == "__main__":
run()