This repository was archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·88 lines (54 loc) · 3.7 KB
/
test.py
File metadata and controls
executable file
·88 lines (54 loc) · 3.7 KB
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
import discordslashcommands as cmd
YOUR_GUILD = 687640485984206871
client = discord.Client()
# This is a new event, called by discordslashcommands
# member is a classic discord.Member object
# interaction is an object who represent the interaction
# interaction.command is the most important
@client.event
async def on_interaction(member, interaction):
if interaction.command.name == "clear": # if the command sended is "clear"
manager = cmd.Manager(client) # create a manager objet to get commands informations
# this object need a discord.Client object to work
if interaction.command.options[0].value == "guild": # if the first option is "guild"
cmds = manager.get_all_guild_commands(YOUR_GUILD) # get the list of commands objects of your application in your guild
else: # the first option is "global"
cmds = manager.get_all_global_commands() # get the list of your global commands
for command in cmds: # loop on commands
command.delete() # delete the current command
interaction.call_on_message(prefix="+") # transform the interaction object to a fake discord.Message object and call the on_message function with him
# this feature allows compatibility with old discord bots
@client.event
async def on_message(message):
print(message.content) # print the content of the fake message generated
print(message.author.roles) # print roles of the member (just to see that it's normal)
# a simple bot discord, like before slash commands
PREFIX = "+"
cmd = message.content.lower()
if cmd == PREFIX + "help premium":
await message.channel.send("here is the premium help")
elif cmd == PREFIX + "help moderation":
await message.channel.send("here is the help of moderation")
elif cmd == PREFIX + "help":
await message.channel.send("here is the normal help")
@client.event
async def on_ready():
manager = cmd.Manager(client) # create a manager after the bot's start
# /!\ this line is very important because it start the interaction listener /!\
command = cmd.Command(name="help", description="display help") #create a simple command
option = cmd.Option(name="category", description="different parts of the help", type=cmd.STRING, required=False) # create an option for this command
option.add_choice(name="premium", value="premium") # add two differents values from this option
option.add_choice(name="moderation", value="moderation") #
command.add_option(option) # add the option to the command
manager.add_guild_command(YOUR_GUILD, command) # put the new command in your guild
# make another command, but a global command this time
command = cmd.Command(name="clear", description="delete all slash commands")
option = cmd.Option(name="zone", description="delete guilds commands or global commands", type=cmd.STRING, required=True)
option.add_choice(name="guild", value="guild")
option.add_choice(name="global", value="global")
command.add_option(option)
manager.add_global_command(command) # with this line, a little bit different, the command is a global command for the application
# global commands need 1h to appear
# /!\ if you run this script 3 times for example, 3 new global commands will appear
client.run("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")