-
Notifications
You must be signed in to change notification settings - Fork 0
/
old_bot.py
59 lines (43 loc) · 1.35 KB
/
old_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
from discord_cah import SeverGame
import discord
from discord.ext import commands
import os
"""
This is a test script to run the discord bot in a specified channel.
Make sure to define the environment variables:
* DISCORD_CAH_BOT_TOKEN: The discord bot token
"""
bot = commands.Bot(command_prefix='?', description="A Cards Bot.")
gms = []
async def start_session(channel_id):
g = SeverGame(bot, channel_id.id, reg_msg_method=False)
gms.append(g)
bot.loop.create_task(g.run())
@bot.event
async def on_message(*args, **kwargs):
msg = args[0]
author = msg.author
if author == bot.user:
return
await bot.process_commands(*args, **kwargs)
for g in gms:
await g.on_message(*args, **kwargs)
@bot.command(pass_context=True)
async def start(ctx):
"""Starts a game."""
channel = ctx.message.channel
if type(channel) == discord.channel.PrivateChannel:
await bot.say("I'm afraid you can't start a fantastical game by yourself. Sorry lad.")
else:
print("non")
await start_session(ctx.message.channel)
print("done")
@bot.event
async def on_ready():
# Set command prefix to be @ mentioning it:
bot.command_prefix = "<@{}> ".format(bot.user.id)
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
bot.run(os.environ['DISCORD_CAH_BOT_TOKEN'])