2024-08-09 12:41:32 +00:00
|
|
|
import nextcord
|
|
|
|
from nextcord.ext import commands
|
|
|
|
from nextcord import TextInputStyle
|
|
|
|
from random import randint
|
|
|
|
import aiosqlite as sqlite3
|
|
|
|
import aiohttp
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
import os
|
|
|
|
|
|
|
|
class RoleView(nextcord.ui.View):
|
2024-08-09 12:59:25 +00:00
|
|
|
def __init__(self,bot):
|
2024-08-09 12:41:32 +00:00
|
|
|
super().__init__(timeout=None)
|
|
|
|
self.bot = bot
|
2024-08-09 14:26:25 +00:00
|
|
|
|
2024-08-09 13:31:47 +00:00
|
|
|
#res = await self.bot.cur.execute(f"SELECT roleid FROM rolebutton WHERE serverid = {self.bot.roleguild.id}")
|
2024-08-09 13:49:30 +00:00
|
|
|
button = nextcord.ui.Button(label="Test", style=nextcord.ButtonStyle.gray, custom_id="rolebutton:821095192831852554")
|
2024-08-09 14:26:25 +00:00
|
|
|
button.callback = self.buttoncallback
|
2024-08-09 13:49:30 +00:00
|
|
|
self.add_item(button)
|
|
|
|
button = nextcord.ui.Button(label="Test 2", style=nextcord.ButtonStyle.gray, custom_id="rolebutton:1058708072064884736")
|
2024-08-09 14:26:25 +00:00
|
|
|
button.callback = self.buttoncallback
|
2024-08-09 13:49:30 +00:00
|
|
|
self.add_item(button)
|
2024-08-09 12:41:32 +00:00
|
|
|
|
2024-08-09 14:41:22 +00:00
|
|
|
async def buttoncallback(self, interaction: nextcord.Interaction) -> None:
|
2024-08-09 19:19:50 +00:00
|
|
|
role = interaction.guild.get_role(int(interaction.data["custom_id"].split(":")[1]))
|
2024-08-09 19:14:33 +00:00
|
|
|
if role in interaction.user.roles:
|
|
|
|
await interaction.user.remove_roles(role, reason=f"{interaction.user.display_name} used role button")
|
|
|
|
await interaction.response.send_message(f"Removed <@{role}> from you!", ephemeral=True, allowed_mentions=nextcord.AllowedMentions.none)
|
|
|
|
else:
|
|
|
|
await interaction.user.add_roles(role, reason=f"{interaction.user.display_name} used role button")
|
|
|
|
await interaction.response.send_message(f"Added <@{role}> to you!", ephemeral=True, allowed_mentions=nextcord.AllowedMentions.none)
|
2024-08-09 14:30:36 +00:00
|
|
|
return
|
2024-08-09 14:26:25 +00:00
|
|
|
|
2024-08-09 13:52:31 +00:00
|
|
|
|
2024-08-09 12:41:32 +00:00
|
|
|
|
2024-08-09 13:33:01 +00:00
|
|
|
class rolebutton(commands.Cog):
|
2024-08-09 12:41:32 +00:00
|
|
|
|
|
|
|
def __init__(self, bot: commands.Bot):
|
|
|
|
self.bot = bot
|
2024-08-09 12:59:25 +00:00
|
|
|
bot.add_view(RoleView(bot))
|
2024-08-09 12:41:32 +00:00
|
|
|
|
|
|
|
@nextcord.slash_command(
|
|
|
|
name="roletest",
|
|
|
|
description="check if the buttons work",
|
|
|
|
)
|
2024-08-09 13:34:45 +00:00
|
|
|
async def roletest(self, interaction: nextcord.Interaction):
|
2024-08-09 12:51:22 +00:00
|
|
|
self.bot.roleguild = interaction.guild
|
2024-08-09 13:34:45 +00:00
|
|
|
await interaction.response.send_message(view=RoleView(self.bot))
|
2024-08-09 12:41:32 +00:00
|
|
|
|
|
|
|
def setup(bot: commands.Bot):
|
2024-08-09 13:33:01 +00:00
|
|
|
bot.add_cog(rolebutton(bot))
|