aboutsummaryrefslogtreecommitdiff
path: root/examples/basic_bot.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2016-01-05 00:07:07 -0500
committerRapptz <[email protected]>2016-01-05 00:07:07 -0500
commit246698254f3b9b77d36078e5fac0121d6d7d4167 (patch)
treed4ad97631e320b38cefdecdd062f1ac71a0c96a5 /examples/basic_bot.py
parent[commands] Add a way to remove commands. (diff)
downloaddiscord.py-246698254f3b9b77d36078e5fac0121d6d7d4167.tar.xz
discord.py-246698254f3b9b77d36078e5fac0121d6d7d4167.zip
Add basic example bot showcasing the commands ext module.
Diffstat (limited to 'examples/basic_bot.py')
-rw-r--r--examples/basic_bot.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/examples/basic_bot.py b/examples/basic_bot.py
new file mode 100644
index 00000000..91ad50fc
--- /dev/null
+++ b/examples/basic_bot.py
@@ -0,0 +1,51 @@
+import discord
+from discord.ext import commands
+import random
+
+bot = commands.Bot(command_prefix='?')
+
+async def on_ready():
+ print('Logged in as')
+ print(bot.user.name)
+ print(bot.user.id)
+ print('------')
+
+async def add(left : int, right : int):
+ await bot.say(left + right)
+
+async def roll(dice : str):
+ 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)
+
+async def choose(*choices : str):
+ await bot.say(random.choice(choices))
+
+async def repeat(times : int, content='repeating...'):
+ for i in range(times):
+ await bot.say(content)
+
+async def joined(member : discord.Member):
+ await bot.say('{0.name} joined in {0.joined_at}'.format(member))
+
[email protected](pass_context=True)
+async def cool(ctx):
+ 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.')
+
+bot.run('email', 'password')