Created
November 1, 2018 05:24
-
-
Save JVero/c808762cbe8166414b991ae91fd46071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import discord | |
from discord.ext import commands | |
import random | |
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) | |
with open('./token.txt') as f: | |
token = f.readline().strip() | |
@bot.event | |
async def on_ready(): | |
print('Logged in as') | |
print(bot.user.name) | |
print(bot.user.id) | |
print('------') | |
@bot.command() | |
async def add(ctx, left: int, right: int): | |
"""Adds two numbers together.""" | |
await ctx.send(left + right) | |
@bot.command() | |
async def roll(ctx, dice: str): | |
"""Rolls a dice in NdN format.""" | |
try: | |
rolls, limit = map(int, dice.split('d')) | |
except Exception: | |
await ctx.send('Format has to be in NdN!') | |
return | |
result = ', '.join(str(random.randint(1, limit)) for r in range(rolls)) | |
await ctx.send(result) | |
@bot.command(description='For when you wanna settle the score some other way') | |
async def choose(ctx, *choices: str): | |
"""Chooses between multiple choices.""" | |
await ctx.send(random.choice(choices)) | |
@bot.command() | |
async def repeat(ctx, times: int, content='repeating...'): | |
"""Repeats a message multiple times.""" | |
for i in range(times): | |
await ctx.send(content) | |
@bot.command() | |
async def joined(ctx, member: discord.Member): | |
"""Says when a member joined.""" | |
await ctx.send('{0.name} joined in {0.joined_at}'.format(member)) | |
@bot.group() | |
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 ctx.send('No, {0.subcommand_passed} is not cool'.format(ctx)) | |
@cool.command(name='bot') | |
async def _bot(ctx): | |
"""Is the bot cool?""" | |
await ctx.send('Yes, the bot is cool.') | |
bot.run(token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment