-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
executable file
·74 lines (56 loc) · 1.64 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
#!/usr/bin/env python
import os
import re
try:
import systemd.daemon
except ModuleNotFoundError:
# for windows
pass
import discord
from dotenv import load_dotenv
import commands
class SSBUActivity(discord.Activity):
def __init__(self, nb_guilds):
super().__init__(
name=f"Super Smash Bros. Ultimate (on {nb_guilds} servers)",
type=discord.ActivityType.playing
)
class SSBUBot(discord.Client):
def __init__(self, intents):
super().__init__(intents=intents)
async def on_ready(self):
nb_guilds = len(self.guilds)
game = SSBUActivity(nb_guilds)
status = discord.Status.online
await self.change_presence(activity=game, status=status)
print(f"{self.user} ready, connected on {nb_guilds} servers")
try:
systemd.daemon.notify("READY=1")
except NameError:
# for windows
pass
async def on_message(self, message):
# Safety first, avoid recursive calls
if message.author == self.user:
return
# Look up for message related to the bot
words = re.split(r"\s+", message.content)
cmds = {
"!ssbu": commands.ssbu,
"!robin": commands.robin,
"!bravery": commands.bravery,
}
if words[0] in cmds:
await cmds[words[0]](message, words)
def main():
intents = discord.Intents.default()
intents.members = True
load_dotenv()
token = os.getenv("DISCORD_TOKEN")
bot = SSBUBot(intents)
try:
bot.run(token)
except:
bot.close()
if __name__ == "__main__":
main()