-
Notifications
You must be signed in to change notification settings - Fork 17
/
discord_bot.py
52 lines (42 loc) · 1.49 KB
/
discord_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
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Module for the Discord bot.
Connecting, sending and receiving messages and doing custom actions.
"""
import logging
import discord
from bot import Bot
class DiscordBot(discord.Client, Bot):
"""Bot implementing the discord protocol"""
def __init__(self):
Bot.__init__(self)
self.CONFIG = {
"token": ""
}
intents = discord.Intents.default()
intents.message_content = True
discord.Client.__init__(self, intents=intents)
def begin(self):
"""Start the bot"""
self.run(self.CONFIG.get("token"))
async def checkMarvinActions(self, message):
"""Check if Marvin should perform any actions"""
words = self.tokenize(message.content)
if self.user.name.lower() in words:
for action in self.ACTIONS:
response = action(words)
if response:
await message.channel.send(response)
else:
for action in self.GENERAL_ACTIONS:
response = action(words)
if response:
await message.channel.send(response)
async def on_message(self, message):
"""Hook run on every message"""
self.MSG_LOG.debug("#%s <%s> %s", message.channel.name, message.author, message.content)
if message.author.name == self.user.name:
# don't react to own messages
return
await self.checkMarvinActions(message)