-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
73 lines (55 loc) · 2.16 KB
/
bot.py
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
from dotenv import load_dotenv
load_dotenv()
# bot.py
import discord, asyncio
from discord import app_commands
from views import AdminView, AuthView
from utils import TOKEN, error_handler
from db import init_db
client = discord.Client(intents=discord.Intents.default())
cmd = app_commands.CommandTree(client)
async def reset_auth_channel(channel):
await channel.set_permissions(channel.guild.default_role, send_messages=False, read_messages=True)
await channel.purge()
await channel.send("Welcome to the auth channel, please send your auth token here", view=AuthView())
@cmd.command(name="admin", description="Admin commands")
@app_commands.default_permissions(administrator=True)
@app_commands.checks.has_permissions(administrator=True)
async def gen_auth_token(interaction):
await interaction.response.send_message("Click a button to activate an admin function", view=AdminView(), ephemeral=True)
@cmd.command(name="generate_auth_channel", description="Create the auth channel in the current channel")
@app_commands.default_permissions(administrator=True)
@app_commands.checks.has_permissions(administrator=True)
async def gen_auth_ch(interaction):
await interaction.response.defer()
await reset_auth_channel(interaction.channel)
@cmd.command(name="clearchat", description="Delete all content in the chat")
@app_commands.default_permissions(administrator=True)
@app_commands.checks.has_permissions(administrator=True)
async def gen_auth_ch(interaction):
await interaction.response.defer()
await interaction.channel.purge()
@gen_auth_token.error
async def gen_auth_token_error(interaction, error):
await error_handler(interaction, error)
@gen_auth_ch.error
async def gen_auth_ch_error(interaction, error):
await error_handler(interaction, error)
async def init_bot():
await asyncio.gather(
cmd.sync(),
init_db()
)
global synced
synced = False
@client.event
async def on_ready():
global synced
print(f'{client.user} has connected to Discord!')
if not synced:
await init_bot()
synced = True
async def setup_hook():
client.add_view(AuthView())
client.setup_hook = setup_hook
client.run(TOKEN)