insert2-cogs/rolebuttons.py
2024-08-09 10:51:59 -04:00

44 lines
No EOL
1.5 KiB
Python

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):
def __init__(self,bot):
super().__init__(timeout=None)
self.bot = bot
#res = await self.bot.cur.execute(f"SELECT roleid FROM rolebutton WHERE serverid = {self.bot.roleguild.id}")
button = nextcord.ui.Button(label="Test", style=nextcord.ButtonStyle.gray, custom_id="rolebutton:821095192831852554")
button.callback = self.buttoncallback
self.add_item(button)
button = nextcord.ui.Button(label="Test 2", style=nextcord.ButtonStyle.gray, custom_id="rolebutton:1058708072064884736")
button.callback = self.buttoncallback
self.add_item(button)
async def buttoncallback(self, interaction: nextcord.Interaction) -> None:
await interaction.response.send_message(f"user requested role {str(interaction.data)}", ephemeral=True)
return
class rolebutton(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
bot.add_view(RoleView(bot))
@nextcord.slash_command(
name="roletest",
description="check if the buttons work",
)
async def roletest(self, interaction: nextcord.Interaction):
self.bot.roleguild = interaction.guild
await interaction.response.send_message(view=RoleView(self.bot))
def setup(bot: commands.Bot):
bot.add_cog(rolebutton(bot))