-
Notifications
You must be signed in to change notification settings - Fork 0
discord
jasper-zanjani edited this page Aug 6, 2020
·
1 revision
pip install discord.pyclient = discord.Client()Client objects expose a decorator that is used for event handlers, functions named after various events:
on_readyon_member_joinon_erroron_message
@client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')Another decorator is exposed for in-chat commands (commands.Bot has to be instantiated first.)
@bot.command(name='roll_dice', help='Simulates rolling dice.')
async def roll(ctx, number_of_dice: int, number_of_sides: int):
dice = [
str(random.choice(range(1, number_of_sides + 1)))
for _ in range(number_of_dice)
]
await ctx.send(', '.join(dice))client.run(token)bot = comands.Bot(command_prefix='!')- argparse ?
- array ?
- asyncio ?
- bisect ?
- csv ?
- ctypes ?
- curses ?
- datetime ?
- functools ?
- getpass ?
- glob ?
- heapq ?
- http ?
- json ?
- logging ?
- optparse ?
- os ?
- pathlib ?
- platform ?
- pythonnet ?
- random ?
- socket ?
- subprocess ?
- sqlite3 ?
- sys ?
- termcolor ?
- threading ?
- trace ?
- typing ?
- unittest ?
- urllib ?
- venv ?
- weakref ?
- winrm ?