index — Deutsche-Haus-Bot @ a56afa3b397d9d8a7952e106aeb69d8a281a03c4

Discord bot to dynamically create voice chats for clubs that boosters can create

works besides no channel deletion

fixed created channel permissions
crispy-caesus 114518720+crispy-caesus@users.noreply.github
Sat, 19 Oct 2024 21:22:24 +0200
commit

a56afa3b397d9d8a7952e106aeb69d8a281a03c4

parent

a30f4c01eb751a2876859dedfb51955dae446667

2 files changed, 57 insertions(+), 21 deletions(-)

jump to
M bot.pybot.py

@@ -1,12 +1,17 @@

import discord import discord.ext.commands +import asyncio + import bot_token import db as database import logic # ======================== STARTUP =========================== # -bot = discord.Bot() +intents = discord.Intents.default() +intents.message_content = True + +bot = discord.Bot(intents=intents) role_converter = discord.ext.commands.RoleConverter() member_converter = discord.ext.commands.MemberConverter()

@@ -130,29 +135,60 @@ print(f"{user.name} Joined The {after.channel.name} VC")

print(after.channel.members) db = database.Database(f"{after.channel.guild.id}.db") - category = discord.utils.get(after.channel.guild.categories, id=await db.get_discord_id("new_channel_category_id")) - if category is None: - print("Kategorie nicht gefunden") + + + + db_response = await db.get_channel_name_role_name_by_member(user.id) + message = "Welchen Club-Kanal willst du öffnen?" + for i in range(len(db_response)): + message += f"\n**{i+1}.** {db_response[i][0]}" + + await after.channel.send(message) + + def check(m): + return m.author == user and m.channel == after.channel + + + done = False + while not done: + + try: + response = await bot.wait_for('message', check=check, timeout=30.0) + except asyncio.TimeoutError: + await after.channel.send("Zu spät") + else: + try: + int(response.content) + except ValueError: + await after.channel.send(":x: Konnte nicht in ganze Zahl umwandeln") + continue + if int(response.content) <= len(db_response) and int(response.content) > 0: + channel_name = db_response[int(response.content)-1][0] + + category = discord.utils.get(after.channel.guild.categories, id=await db.get_discord_id("new_channel_category_id")) + if category is None: + print("Kategorie nicht gefunden") + + role = discord.utils.get(after.channel.guild.roles, id=db_response[int(response.content)-1][1]) + if role is None: + print("Rolle nicht gefunden") - role = discord.utils.get(after.channel.guild.roles, id=await db.get_discord_id("booster_role_id")) - if role is None: - print("Rolle nicht gefunden") + overwrites = { + after.channel.guild.default_role: discord.PermissionOverwrite(view_channel=False), # @everyone can't view + role: discord.PermissionOverwrite(view_channel=True, connect=True) # Role can view and connect + } - overwrites = { - after.channel.guild.default_role: discord.PermissionOverwrite(view_channel=False), # @everyone can't view - role: discord.PermissionOverwrite(view_channel=True, connect=True) # Role can view and connect - } + voice_channel = await category.create_voice_channel( + name = channel_name, + overwrites=overwrites + ) + done = True + else: + await after.channel.send(":x: Nicht zulässige Zahl") - response = await db.get_channel_name_role_name_by_member(user.id) - channel_name = response[0][0] - print(f"{type(channel_name)}: {channel_name}") - - voice_channel = await category.create_voice_channel( - name = channel_name, - overwrites=overwrites - ) + if user.voice: + await user.move_to(voice_channel) - print(f"Voice channel '{channel_name}' created under the category '{category}' and restricted to the role '{role}'.") bot.run(bot_token.token)
M db.pydb.py

@@ -178,7 +178,7 @@ async with aiosqlite.connect(self.db_name) as db:

async with db.execute("SELECT club_id FROM members WHERE user_id = ?;", (user_id,)) as cursor: async for club_id in cursor: print(f"{type(club_id[0])}: {club_id[0]}") - async with db.execute("SELECT channel_name, role_name FROM clubs WHERE id = ?;", (club_id[0], )) as cursor2: + async with db.execute("SELECT channel_name, role_id FROM clubs WHERE id = ?;", (club_id[0], )) as cursor2: async for club in cursor2: clubs.append(club) print(clubs)