-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
75 lines (55 loc) · 1.8 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
74
75
import json
import nextcord
from nextcord.ext import commands
import utils.global_variables as gv
from utils.languages import init as langs_init
from utils.settings.bot_ban import get_ban_type
import utils.sql as db
langs_init()
db.init()
from handlers.message_handler import handle_message
from handlers.slash_commands import register_slash_commands
from handlers.context_menu_commands import register_context_menu_commands
intents = nextcord.Intents.all()
intents.typing = False
intents.presences = False
def load_config():
with open("config/config.json", "r", encoding='utf-8') as f:
return json.load(f)
config = load_config()
bot = commands.Bot(
owner_id=config.get('owner-id'),
command_prefix=config['default-prefix'],
intents=intents
)
gv.set('bot', bot)
gv.set('client', bot)
@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')
@bot.event
async def on_message(message):
await handle_message(bot, message)
register_slash_commands(bot)
register_context_menu_commands(bot)
@bot.event
async def on_application_command_error(interaction: nextcord.Interaction, error: Exception):
# This function is used to ignore errors that occur when preventing commands for banned users or guilds
if not isinstance(
error,
(
nextcord.errors.ApplicationCheckFailure,
nextcord.errors.InteractionResponded,
),
):
# Handle other types of errors or re-raise them
raise error
@bot.event
async def on_guild_join(guild):
if get_ban_type(guild.id, is_guild=True) == 'instant_leave':
await guild.leave()
print(f"Left banned guild: {guild.name} (ID: {guild.id})")
if config.get('production', False) == True:
bot.run(config['tokens']['main'])
else:
bot.run(config['tokens']['test'])