-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
88 lines (69 loc) · 2.68 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import discord
from discord.ext import commands
from discord.ui import Modal, TextInput
import os
import dotenv
import jishaku
# Defines a custom Modal with questions
# that user has to answer. The callback function
# of this class is called when the user submits the modal
class Modal(Modal):
def __init__(self) -> None:
super().__init__("AddBot:")
# Set the questions that will be shown in the modal
# The placeholder is what will be shown when nothing is typed
#self.add_item(TextInput(label="What reason do you have to add your bot?"))
# Provide value argument to prefill the input
# The style parameter allows you to set the style of the input
# You can choose from short and long
self.add_item(
TextInput(
label="Your Reason for Adding the bot is?:",
value="",
style=discord.TextInputStyle.long,
)
)
async def callback(self, interaction: discord.Interaction):
# Use the interaction object to send a response message containing
# the user's name or choice. The self object refers to the
# Modal object, and the values attribute gets a list of the user's
# answers. We only want the first one.
await interaction.response.send_message(
f"Sent Reason: {self.children[0].value} to my boss."
)
class ModalView(discord.ui.View):
@discord.ui.button(label="Open Modal", style=discord.ButtonStyle.green)
async def open_modal(self, button: discord.Button, interaction: discord.Interaction):
# Create the modal
modal = Modal()
# Sending a message containing our modal
await interaction.response.send_modal(modal)
class Bot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=commands.when_mentioned_or("$"),
intents=discord.Intents(guilds=True, messages=True),
slash_commands=True,
)
async def on_ready(self):
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
bot = Bot()
@bot.command()
async def form(ctx: commands.Context):
"""Sends a message with our modal"""
# Create the view containing our modal
view = ModalView()
# Sending a message containing our view
await ctx.send("Click to open modal:", view=view)
# Can also be used from slash commands directly
@bot.command(message_command=False)
async def modal(ctx: commands.Context):
# Create the modal
modal = Modal()
# Sending our modal
await ctx.interaction.response.send_modal(modal)
dotenv.load_dotenv()
bot.load_extension("jishaku")
bot.run(os.environ["TOKEN"])
#ngl very cool