-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.py
67 lines (53 loc) · 1.62 KB
/
math.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import discord
from discord.ext import commands, dyn
import os
bot = dyn.Bot(
command_prefix="!", intents=discord.Intents(messages=True, message_content=True)
)
# `style`, `label`, `emoji`, are optional, only `custom_id` is required
@bot.button(
style=discord.ButtonStyle.primary,
label="Add",
template="add:{x},{y}",
)
async def add(ctx: dyn.Context, *, x: int, y: int) -> None:
await ctx.respond(f"{x} + {y} = {x + y}", ephemeral=True)
@bot.button(
style=discord.ButtonStyle.primary,
label="Subtract",
template="sub:{x},{y}",
)
async def sub(ctx: dyn.Context, *, x: int, y: int) -> None:
await ctx.respond(f"{x} - {y} = {x - y}", ephemeral=True)
@bot.button(
style=discord.ButtonStyle.primary,
label="Multiply",
template="mul:{x},{y}",
)
async def mul(ctx: dyn.Context, *, x: int, y: int) -> None:
await ctx.respond(f"{x} * {y} = {x * y}", ephemeral=True)
@bot.button(
style=discord.ButtonStyle.primary,
label="Divide",
template="div:{x},{y}",
)
async def div(ctx: dyn.Context, *, x: int, y: int) -> None:
if y == 0:
await ctx.respond(f"Cannot divide by zero", ephemeral=True)
return
await ctx.respond(f"{x} / {y} = {x / y}", ephemeral=True)
@bot.command()
async def math(ctx: commands.Context, x: int, y: int) -> None:
await ctx.send(
"Math is fun",
view=(
dyn.ViewBuilder()
.add_component(add(x=x, y=y))
.add_component(sub(x=x, y=y))
.add_component(mul(x=x, y=y))
.add_component(div(x=x, y=y))
.build()
),
)
token = os.environ["TOKEN"]
bot.run(token)