-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
51 lines (37 loc) · 1.42 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
from datetime import datetime
import logging
import discord
from discord.ext import commands
class Bot(commands.Bot):
'''Extended bot class.'''
def __init__(self):
'''Build default bot with "!" prefix and member intents.'''
# Bot building (native discord.py commands won't be used)
intents = discord.Intents.default()
intents.members = intents.message_content = True
super().__init__(command_prefix="!", intents=intents)
async def setup_hook(self):
self.tree.copy_global_to(guild=discord.Object(id=987832530826833920))
await self.tree.sync()
# Global bot object
bot: commands.Bot = Bot()
@bot.command()
async def sync(ctx):
'''Prefix command; sync bot slash commands.'''
if ctx.author.id == 315940379553955844:
await bot.tree.sync()
await ctx.send('Command tree synced.')
else:
await ctx.send('You must be an admin to use this command!')
async def check(interaction: discord.Interaction) -> bool:
'''Log user and command name before each slash command run.'''
username = interaction.user.name
command = interaction.command.qualified_name
logging.info(
f"> \033[1m{username}\033[0m "
f"used command \ue0b6\033[30;107m/{command}\033[0m\ue0b4 "
f"({datetime.utcnow()})"
)
return True # command should be run
# Override global slash commands checker
bot.tree.interaction_check = check