-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
77 lines (60 loc) · 1.96 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
76
77
"""discord api connection"""
import os
import asyncio
import discord
from discord.ext import commands
import discordlists
from cogs.api.redis import RedisClient
import healthcheck
TOKEN = os.getenv("TOKEN", "")
class MyBot(commands.AutoShardedBot):
"""Bot setup class."""
async def setup_hook(self):
await healthcheck.start(self)
self.remove_command("help")
await self.load_extension("cogs.beamng_mp")
await self.load_extension("cogs.admin_only")
await self.load_extension("cogs.other")
await self.load_extension("cogs.sync")
intents = discord.Intents.default()
bot = MyBot(fetch_offline_members=False, command_prefix="mp!", intents=intents)
@bot.event
async def on_ready():
"""On bot ready"""
print("bot started \n")
print(f"Connected on {len(bot.guilds)} server(s)")
redis_client = RedisClient()
await redis_client.redis_connect()
# sync /sync
await bot.tree.sync(guild=discord.Object(770746735533228083))
top_token = os.getenv("TOP_TOKEN", "")
# https://botblock.org/
if top_token != "":
print("running prod")
api = discordlists.Client(bot)
api.set_auth("top.gg", top_token)
api.start_loop()
while True:
try:
await bot.change_presence(
activity=discord.Game(f"in {len(bot.guilds)} servers")
)
await asyncio.sleep(900)
except Exception as e:
print(e)
# dont give a error if a command doesn't exist
@bot.event
async def on_command_error(ctx, error):
"""On any error"""
if isinstance(error, commands.CommandNotFound):
return
elif isinstance(error, commands.MissingRequiredArgument):
return
elif isinstance(error, commands.MissingPermissions):
embed = discord.Embed(
color=0xE74C3C, description="Your not allowed to use this command"
)
await ctx.send(embed=embed)
raise error
# run the bot
bot.run(TOKEN)