/ParInternationalFreedom
Created 2 years, 6 months ago...
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 |
import disnake
from disnake.ext import commands
class SelectGames(disnake.ui.Select):
def __init__(self):
options = [
disnake.SelectOption(label="Dota 2", value="1069157308388614144", emoji="<:dota:1070792276793626715>"),
disnake.SelectOption(label="Valorant", value="1069157349564100629",
emoji="<:valorant:1070792273102651584>"),
disnake.SelectOption(label="Genshin Impact", value="1070712380692111410",
emoji="<:genshin:1070792271055831110>")]
super().__init__(placeholder="Select a game", options=options, custom_id="games", min_values=0, max_values=3)
async def callback(self, interaction: disnake.MessageInteraction):
await interaction.response.defer()
all_roles = {1069157308388614144, 1069157349564100629, 1070712380692111410}
to_remove = []
to_add = []
if not interaction.values:
for role_id in all_roles:
role = interaction.guild.get_role(role_id)
to_remove.append(role)
await interaction.author.remove_roles(*to_remove, reason="Removed all roles")
else:
chosen_roles = {int(value) for value in interaction.values}
ids_to_remove = all_roles - chosen_roles
for role_id in ids_to_remove:
role = interaction.guild.get_role(role_id)
to_remove.append(role)
for role_id in chosen_roles:
role = interaction.guild.get_role(role_id)
to_add.append(role)
await interaction.author.remove_roles(*to_remove, reason="Removed roles")
await interaction.author.add_roles(*to_add, reason="Added roles")
class GameRoles(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.persistents_views_added = False
@commands.command()
async def games(self, ctx):
view = disnake.ui.View(timeout=None)
view.add_item(SelectGames())
embed = disnake.Embed(color=0x2F3136)
embed.set_author(name="Game roles:")
embed.description = "Under this post, you can choose your role by clicking on the appropriate" \
" role button in the selection menu.\n\n" \
"<:dota:1070792276793626715> - Dota 2\n" \
"<:valorant:1070792273102651584> - Valorant\n" \
"<:genshin:1070792271055831110> - Genshin Impact"
embed.set_image(url="https://i.imgur.com/QzB7q9J.png")
await ctx.send(embed=embed, view=view)
@commands.Cog.listener()
async def on_connect(self):
if self.persistents_views_added:
return
view = disnake.ui.View(timeout=None)
view.add_item(SelectGames())
self.bot.add_view(view, message_id=1070794323689476178)
def setup(bot):
bot.add_cog(GameRoles(bot))