aboutsummaryrefslogtreecommitdiff
path: root/examples/basic_bot.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-01-12 01:29:37 -0500
committerRapptz <[email protected]>2016-01-12 01:29:37 -0500
commit8d76e7095e724bfe2c4577559b940df653db6227 (patch)
tree89e398fb246a5aacd4e8ca082a3a9d968950c98a /examples/basic_bot.py
parent[commands] Fix handling of nested subcommand help handling. (diff)
downloaddiscord.py-8d76e7095e724bfe2c4577559b940df653db6227.tar.xz
discord.py-8d76e7095e724bfe2c4577559b940df653db6227.zip
Basic bot example now shows documenting for the built-in help command.
Diffstat (limited to 'examples/basic_bot.py')
-rw-r--r--examples/basic_bot.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/examples/basic_bot.py b/examples/basic_bot.py
index 91ad50fc..81ce0ab4 100644
--- a/examples/basic_bot.py
+++ b/examples/basic_bot.py
@@ -2,7 +2,11 @@ import discord
from discord.ext import commands
import random
-bot = commands.Bot(command_prefix='?')
+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():
@@ -13,10 +17,12 @@ async def on_ready():
@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:
@@ -26,26 +32,34 @@ async def roll(dice : str):
result = ', '.join(str(random.randint(1, limit)) for r in range(rolls))
await bot.say(result)
[email protected](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))
-async def bob():
- await bot.say('Yes, bob is cool.')
[email protected](name='bot')
+async def _bot():
+ """Is the bot cool?"""
+ await bot.say('Yes, the bot is cool.')
bot.run('email', 'password')