-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
66 lines (55 loc) · 1.86 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
import discord
from discord.ext import commands
import random
import os
description = '''An example bot to showcase the discord.ext.commands extension
module.
There are a number of utility commands being showcased here.'''
bot = commands.Bot(command_prefix='?', description=description)
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
async def add(left : int, right : int):
"""Adds two numbers together."""
await bot.say(left + right)
@bot.command()
async def roll(dice : str):
"""Rolls a dice in NdN format."""
try:
rolls, limit = map(int, dice.split('d'))
except Exception:
await bot.say('Format has to be in NdN!')
return
result = ', '.join(str(random.randint(1, limit)) for r in range(rolls))
await bot.say(result)
@bot.command(description='For when you wanna settle the score some other way')
async def choose(*choices : str):
"""Chooses between multiple choices."""
await bot.say(random.choice(choices))
@bot.command()
async def repeat(times : int, content='repeating...'):
"""Repeats a message multiple times."""
for i in range(times):
await bot.say(content)
@bot.command()
async def joined(member : discord.Member):
"""Says when a member joined."""
await bot.say('{0.name} joined in {0.joined_at}'.format(member))
@bot.group(pass_context=True)
async def cool(ctx):
"""Says if a user is cool.
In reality this just checks if a subcommand is being invoked.
"""
if ctx.invoked_subcommand is None:
await bot.say('No, {0.subcommand_passed} is not cool'.format(ctx))
@cool.command(name='bot')
async def _bot():
"""Is the bot cool?"""
await bot.say('Yes, the bot is cool.')
if not os.environ.get('TOKEN'):
print("no token found!")
bot.run(os.environ.get('TOKEN').strip('"'))