mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 07:26:17 +00:00
Check and handle login failure in the examples provided for using this library. This is a common error condition that should be handled by any script using this library.
29 lines
689 B
Python
29 lines
689 B
Python
import discord
|
|
import time
|
|
|
|
client = discord.Client()
|
|
client.login('email', 'password')
|
|
|
|
if not client.is_logged_in:
|
|
print('Logging in to Discord failed')
|
|
exit(1)
|
|
|
|
@client.event
|
|
def on_ready():
|
|
print('Connected!')
|
|
print('Username: ' + client.user.name)
|
|
print('ID: ' + client.user.id)
|
|
|
|
@client.event
|
|
def on_message(message):
|
|
if message.content.startswith('!editme'):
|
|
msg = client.send_message(message.author, '10')
|
|
time.sleep(3)
|
|
client.edit_message(msg, '40')
|
|
|
|
@client.event
|
|
def on_message_edit(before, after):
|
|
client.send_message(after.channel, '**{}** edited their message:\n{}'.format(after.author.name, before.content))
|
|
|
|
client.run()
|