Browse Source

Update example code.

pull/57/head
Rapptz 9 years ago
parent
commit
e87d54dd12
  1. 16
      examples/deleted.py
  2. 9
      examples/echo.py
  3. 20
      examples/edits.py
  4. 10
      examples/new_member.py
  5. 10
      examples/reply.py

16
examples/deleted.py

@ -1,22 +1,22 @@
import discord
client = discord.Client()
client.login('email', 'password')
@client.event
@client.async_event
def on_ready():
print('Connected!')
print('Username: ' + client.user.name)
print('ID: ' + client.user.id)
@client.event
@client.async_event
def on_message(message):
if message.content.startswith('!deleteme'):
msg = client.send_message(message.channel, 'I will delete myself now...')
client.delete_message(msg)
msg = yield from client.send_message(message.channel, 'I will delete myself now...')
yield from client.delete_message(msg)
@client.event
@client.async_event
def on_message_delete(message):
client.send_message(message.channel, '{} has deleted the message:\n{}'.format(message.author.name, message.content))
fmt = '{0.author.name} has deleted the message:\n{0.content}'
yield from client.send_message(message.channel, fmt.format(message))
client.run()
client.run('email', 'password')

9
examples/echo.py

@ -1,17 +1,16 @@
import discord
client = discord.Client()
client.login('email', 'password')
@client.event
@client.async_event
def on_ready():
print('Connected!')
print('Username: ' + client.user.name)
print('ID: ' + client.user.id)
@client.event
@client.async_event
def on_message(message):
if message.author.id != client.user.id:
client.send_message(message.channel, message.content)
yield from client.send_message(message.channel, message.content)
client.run()
client.run('email', 'password')

20
examples/edits.py

@ -1,24 +1,24 @@
import discord
import time
import asyncio
client = discord.Client()
client.login('email', 'password')
@client.event
@client.async_event
def on_ready():
print('Connected!')
print('Username: ' + client.user.name)
print('ID: ' + client.user.id)
@client.event
@client.async_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')
msg = yield from client.send_message(message.author, '10')
yield from asyncio.sleep(3)
yield from client.edit_message(msg, '40')
@client.event
@client.async_event
def on_message_edit(before, after):
client.send_message(after.channel, '**{}** edited their message:\n{}'.format(after.author.name, before.content))
fmt = '**{0.author}** edited their message:\n{1.content}'
yield from client.send_message(after.channel, fmt.format(after, before))
client.run()
client.run('email', 'password')

10
examples/new_member.py

@ -1,18 +1,18 @@
import discord
client = discord.Client()
client.login('email', 'password')
@client.event
@client.async_event
def on_member_join(member):
server = member.server
client.send_message(server, 'Welcome {0} to {1.name}!'.format(member.mention(), server))
fmt = 'Welcome {0} to {1.name}!'
yield from client.send_message(server, fmt.format(member.mention(), server))
@client.event
@client.async_event
def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run()
client.run('email', 'password')

10
examples/reply.py

@ -1,22 +1,22 @@
import discord
client = discord.Client()
client.login('email', 'password')
@client.event
@client.async_event
def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hello'):
client.send_message(message.channel, 'Hello {}!'.format(message.author.mention()))
msg = 'Hello {}!'.format(message.author.mention()
yield from client.send_message(message.channel, msg))
@client.event
@client.async_event
def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run()
client.run('email', 'password')

Loading…
Cancel
Save