mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-16 18:59:09 +00:00
Use Python3Lexer instead of PythonLexer for pygments.
This commit is contained in:
parent
d672f84932
commit
f588876587
@ -49,7 +49,7 @@ def when_mentioned_or(*prefixes):
|
|||||||
Example
|
Example
|
||||||
--------
|
--------
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'))
|
bot = commands.Bot(command_prefix=commands.when_mentioned_or('!'))
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ class BotBase(GroupMixin):
|
|||||||
Example
|
Example
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
@bot.check
|
@bot.check
|
||||||
def whitelist(ctx):
|
def whitelist(ctx):
|
||||||
@ -373,7 +373,7 @@ class BotBase(GroupMixin):
|
|||||||
Example
|
Example
|
||||||
--------
|
--------
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
async def on_ready(): pass
|
async def on_ready(): pass
|
||||||
async def my_message(message): pass
|
async def my_message(message): pass
|
||||||
@ -422,7 +422,7 @@ class BotBase(GroupMixin):
|
|||||||
Example
|
Example
|
||||||
--------
|
--------
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
@bot.listen()
|
@bot.listen()
|
||||||
async def on_message(message):
|
async def on_message(message):
|
||||||
|
@ -998,7 +998,7 @@ def check(predicate):
|
|||||||
|
|
||||||
Creating a basic check to see if the command invoker is you.
|
Creating a basic check to see if the command invoker is you.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
def check_if_it_is_me(ctx):
|
def check_if_it_is_me(ctx):
|
||||||
return ctx.message.author.id == 85309593344815104
|
return ctx.message.author.id == 85309593344815104
|
||||||
@ -1010,7 +1010,7 @@ def check(predicate):
|
|||||||
|
|
||||||
Transforming common checks into its own decorator:
|
Transforming common checks into its own decorator:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
def is_me():
|
def is_me():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
@ -1076,7 +1076,7 @@ def has_any_role(*names):
|
|||||||
Example
|
Example
|
||||||
--------
|
--------
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
@commands.has_any_role('Library Devs', 'Moderators')
|
@commands.has_any_role('Library Devs', 'Moderators')
|
||||||
@ -1106,7 +1106,7 @@ def has_permissions(**perms):
|
|||||||
Example
|
Example
|
||||||
---------
|
---------
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
@commands.has_permissions(manage_messages=True)
|
@commands.has_permissions(manage_messages=True)
|
||||||
|
@ -476,13 +476,13 @@ class Guild(Hashable):
|
|||||||
|
|
||||||
Creating a basic channel:
|
Creating a basic channel:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
channel = await guild.create_text_channel('cool-channel')
|
channel = await guild.create_text_channel('cool-channel')
|
||||||
|
|
||||||
Creating a "secret" channel:
|
Creating a "secret" channel:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
overwrites = {
|
overwrites = {
|
||||||
guild.default_role: discord.PermissionOverwrite(read_messages=False),
|
guild.default_role: discord.PermissionOverwrite(read_messages=False),
|
||||||
|
@ -293,7 +293,7 @@ class Member(discord.abc.Messageable, _BaseUser):
|
|||||||
|
|
||||||
Basically equivalent to:
|
Basically equivalent to:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
channel.permissions_for(self)
|
channel.permissions_for(self)
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ class BaseUser(_BaseUser):
|
|||||||
|
|
||||||
Basically equivalent to:
|
Basically equivalent to:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
channel.permissions_for(self)
|
channel.permissions_for(self)
|
||||||
|
|
||||||
|
@ -188,19 +188,19 @@ def get(iterable, **attrs):
|
|||||||
|
|
||||||
Basic usage:
|
Basic usage:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
member = discord.utils.get(message.guild.members, name='Foo')
|
member = discord.utils.get(message.guild.members, name='Foo')
|
||||||
|
|
||||||
Multiple attribute matching:
|
Multiple attribute matching:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
channel = discord.utils.get(guild.channels, name='Foo', type=ChannelType.voice)
|
channel = discord.utils.get(guild.channels, name='Foo', type=ChannelType.voice)
|
||||||
|
|
||||||
Nested attribute matching:
|
Nested attribute matching:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
channel = discord.utils.get(client.get_all_channels(), guild__name='Cool', name='general')
|
channel = discord.utils.get(client.get_all_channels(), guild__name='Cool', name='general')
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ happens, you will receive an event about it and you can then respond to it.
|
|||||||
|
|
||||||
A quick example to showcase how events work:
|
A quick example to showcase how events work:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
@ -626,7 +626,7 @@ For example, to wait for a reaction: ::
|
|||||||
Since this function now can return multiple arguments, the ``timeout`` parameter will now raise a ``asyncio.TimeoutError``
|
Since this function now can return multiple arguments, the ``timeout`` parameter will now raise a ``asyncio.TimeoutError``
|
||||||
when reached instead of setting the return to ``None``. For example:
|
when reached instead of setting the return to ``None``. For example:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
def pred(m):
|
def pred(m):
|
||||||
return m.author == message.author and m.channel == message.channel
|
return m.author == message.author and m.channel == message.channel
|
||||||
@ -726,7 +726,7 @@ In v1.0, the :class:`.Context` has received a lot of changes with how it's retri
|
|||||||
|
|
||||||
The biggest change is that ``pass_context=True`` is now the default behaviour. Ergo:
|
The biggest change is that ``pass_context=True`` is now the default behaviour. Ergo:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
# before
|
# before
|
||||||
@bot.command()
|
@bot.command()
|
||||||
@ -768,7 +768,7 @@ provided one.
|
|||||||
|
|
||||||
For example, if you want to add some functionality to the context:
|
For example, if you want to add some functionality to the context:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
class MyContext(commands.Context):
|
class MyContext(commands.Context):
|
||||||
@property
|
@property
|
||||||
@ -778,7 +778,7 @@ For example, if you want to add some functionality to the context:
|
|||||||
Then you can use :meth:`~ext.commands.Bot.get_context` inside :func:`on_message` with combination with
|
Then you can use :meth:`~ext.commands.Bot.get_context` inside :func:`on_message` with combination with
|
||||||
:meth:`~ext.commands.Bot.invoke` to use your custom context:
|
:meth:`~ext.commands.Bot.invoke` to use your custom context:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
class MyBot(commands.Bot):
|
class MyBot(commands.Bot):
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
@ -787,7 +787,7 @@ Then you can use :meth:`~ext.commands.Bot.get_context` inside :func:`on_message`
|
|||||||
|
|
||||||
Now inside your commands you will have access to your custom context:
|
Now inside your commands you will have access to your custom context:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def secret(ctx):
|
async def secret(ctx):
|
||||||
|
@ -25,7 +25,7 @@ possible, the events must be decorated with ``@asyncio.coroutine``.
|
|||||||
|
|
||||||
Before:
|
Before:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
def on_message(message):
|
def on_message(message):
|
||||||
@ -33,7 +33,7 @@ Before:
|
|||||||
|
|
||||||
After:
|
After:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -42,7 +42,7 @@ After:
|
|||||||
|
|
||||||
Or in Python 3.5+:
|
Or in Python 3.5+:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
@client.event
|
@client.event
|
||||||
async def on_message(message):
|
async def on_message(message):
|
||||||
@ -51,7 +51,7 @@ Or in Python 3.5+:
|
|||||||
Because there is a lot of typing, a utility decorator (:meth:`Client.async_event`) is provided
|
Because there is a lot of typing, a utility decorator (:meth:`Client.async_event`) is provided
|
||||||
for easier registration. For example:
|
for easier registration. For example:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
@client.async_event
|
@client.async_event
|
||||||
def on_message(message):
|
def on_message(message):
|
||||||
@ -70,7 +70,7 @@ was changed.
|
|||||||
|
|
||||||
Before:
|
Before:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
def on_channel_update(channel): pass
|
def on_channel_update(channel): pass
|
||||||
def on_member_update(member): pass
|
def on_member_update(member): pass
|
||||||
@ -82,7 +82,7 @@ Before:
|
|||||||
|
|
||||||
After:
|
After:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
def on_channel_update(before, after): pass
|
def on_channel_update(before, after): pass
|
||||||
def on_member_update(before, after): pass
|
def on_member_update(before, after): pass
|
||||||
@ -104,13 +104,13 @@ for the computation to be done. For example...
|
|||||||
|
|
||||||
Before:
|
Before:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
client.send_message(message.channel, 'Hello')
|
client.send_message(message.channel, 'Hello')
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
yield from client.send_message(message.channel, 'Hello')
|
yield from client.send_message(message.channel, 'Hello')
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ The affected attributes are as follows:
|
|||||||
|
|
||||||
Some examples of previously valid behaviour that is now invalid
|
Some examples of previously valid behaviour that is now invalid
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
if client.servers[0].name == "test":
|
if client.servers[0].name == "test":
|
||||||
# do something
|
# do something
|
||||||
@ -145,7 +145,7 @@ Some examples of previously valid behaviour that is now invalid
|
|||||||
Since they are no longer ``list``\s, they no longer support indexing or any operation other than iterating.
|
Since they are no longer ``list``\s, they no longer support indexing or any operation other than iterating.
|
||||||
In order to get the old behaviour you should explicitly cast it to a list.
|
In order to get the old behaviour you should explicitly cast it to a list.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
servers = list(client.servers)
|
servers = list(client.servers)
|
||||||
# work with servers
|
# work with servers
|
||||||
@ -165,7 +165,7 @@ The common places where this was changed was in the server region, member status
|
|||||||
|
|
||||||
Before:
|
Before:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
server.region == 'us-west'
|
server.region == 'us-west'
|
||||||
member.status == 'online'
|
member.status == 'online'
|
||||||
@ -173,7 +173,7 @@ Before:
|
|||||||
|
|
||||||
After:
|
After:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
server.region == discord.ServerRegion.us_west
|
server.region == discord.ServerRegion.us_west
|
||||||
member.status = discord.Status.online
|
member.status = discord.Status.online
|
||||||
@ -276,14 +276,14 @@ However, in order to do that you must pass in your credentials to :meth:`Client.
|
|||||||
|
|
||||||
Basically, before:
|
Basically, before:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
client.login('token')
|
client.login('token')
|
||||||
client.run()
|
client.run()
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
client.run('token')
|
client.run('token')
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ This is a utility function that abstracts the event loop for you. There's no nee
|
|||||||
the run call to be blocking and out of your control. Indeed, if you want control of the
|
the run call to be blocking and out of your control. Indeed, if you want control of the
|
||||||
event loop then doing so is quite straightforward:
|
event loop then doing so is quite straightforward:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -15,7 +15,7 @@ Let's make a bot that replies to a specific message and walk you through it.
|
|||||||
|
|
||||||
It looks something like this:
|
It looks something like this:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python3
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user