added basic bot functionality.

This commit is contained in:
2018-04-26 11:06:58 +01:00
parent 9f5fe51c35
commit b8054521ae
2 changed files with 53 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
import logging
import discord
import asyncio
from django.core.management.base import BaseCommand
logger = logging.getLogger('discord')
# https://discordapp.com/oauth2/authorize?client_id=XXXXXXXXXXXX&scope=bot
TOKEN = 'XXXXXXXXXXXXXXXXX'
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hello'):
msg = 'Hello {0.author.mention}'.format(message)
await client.send_message(message.channel, msg)
async def check_groups():
default_channel = None
for channel in client.get_all_channels():
if channel.is_default:
default_channel = channel
while True:
await client.send_message(default_channel, 'Periodic')
await asyncio.sleep(10)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
asyncio.Task(check_groups())
class Command(BaseCommand):
def __init__(self):
super().__init__()
def handle(self, *args, **options):
client.run(TOKEN)

View File

@@ -4,3 +4,4 @@ django-allauth
django-bootstrap4
python-dateutil
bleach
git+https://github.com/Rapptz/discord.py@1863a1c#egg=discord.py