aboutsummaryrefslogtreecommitdiff
path: root/docs/ext
diff options
context:
space:
mode:
authorSebastian Law <[email protected]>2021-04-08 06:31:06 -0700
committerGitHub <[email protected]>2021-04-08 09:31:06 -0400
commit05c123f3aba623e24b8fe269b5e424ad00940245 (patch)
tree7a4aa5ae15ed1bc55da5dd11cb8eccfb9356992d /docs/ext
parentUse f-strings in more places that were missed. (diff)
downloaddiscord.py-05c123f3aba623e24b8fe269b5e424ad00940245.tar.xz
discord.py-05c123f3aba623e24b8fe269b5e424ad00940245.zip
Use f-strings in more places that were missed
Diffstat (limited to 'docs/ext')
-rw-r--r--docs/ext/commands/api.rst2
-rw-r--r--docs/ext/commands/cogs.rst6
-rw-r--r--docs/ext/commands/commands.rst17
-rw-r--r--docs/ext/commands/extensions.rst2
4 files changed, 14 insertions, 13 deletions
diff --git a/docs/ext/commands/api.rst b/docs/ext/commands/api.rst
index c7b6659f..6fa552d6 100644
--- a/docs/ext/commands/api.rst
+++ b/docs/ext/commands/api.rst
@@ -338,7 +338,7 @@ Converters
@commands.command()
async def test(ctx, numbers: Greedy[int], reason: str):
- await ctx.send("numbers: {}, reason: {}".format(numbers, reason))
+ await ctx.send(f"numbers: {numbers}, reason: {reason}")
An invocation of ``[p]test 1 2 3 4 5 6 hello`` would pass ``numbers`` with
``[1, 2, 3, 4, 5, 6]`` and ``reason`` with ``hello``\.
diff --git a/docs/ext/commands/cogs.rst b/docs/ext/commands/cogs.rst
index 589a94c2..25bb1a0b 100644
--- a/docs/ext/commands/cogs.rst
+++ b/docs/ext/commands/cogs.rst
@@ -33,16 +33,16 @@ This example cog defines a ``Greetings`` category for your commands, with a sing
async def on_member_join(self, member):
channel = member.guild.system_channel
if channel is not None:
- await channel.send('Welcome {0.mention}.'.format(member))
+ await channel.send(f'Welcome {member.mention}.')
@commands.command()
async def hello(self, ctx, *, member: discord.Member = None):
"""Says hello"""
member = member or ctx.author
if self._last_member is None or self._last_member.id != member.id:
- await ctx.send('Hello {0.name}~'.format(member))
+ await ctx.send(f'Hello {member.name}~')
else:
- await ctx.send('Hello {0.name}... This feels familiar.'.format(member))
+ await ctx.send(f'Hello {member.name}... This feels familiar.')
self._last_member = member
A couple of technical notes to take into consideration:
diff --git a/docs/ext/commands/commands.rst b/docs/ext/commands/commands.rst
index 5e13425b..3c572536 100644
--- a/docs/ext/commands/commands.rst
+++ b/docs/ext/commands/commands.rst
@@ -99,7 +99,7 @@ Since positional arguments are just regular Python arguments, you can have as ma
@bot.command()
async def test(ctx, arg1, arg2):
- await ctx.send('You passed {} and {}'.format(arg1, arg2))
+ await ctx.send(f'You passed {arg1} and {arg2}')
Variable
++++++++++
@@ -111,7 +111,8 @@ similar to how variable list parameters are done in Python:
@bot.command()
async def test(ctx, *args):
- await ctx.send('{} arguments: {}'.format(len(args), ', '.join(args)))
+ arguments = ', '.join(args)
+ await ctx.send(f'{len(args)} arguments: {arguments}')
This allows our user to accept either one or many arguments as they please. This works similar to positional arguments,
so multi-word parameters should be quoted.
@@ -256,7 +257,7 @@ An example converter:
class Slapper(commands.Converter):
async def convert(self, ctx, argument):
to_slap = random.choice(ctx.guild.members)
- return '{0.author} slapped {1} because *{2}*'.format(ctx, to_slap, argument)
+ return f'{ctx.author} slapped {to_slap} because *{argument}*'
@bot.command()
async def slap(ctx, *, reason: Slapper):
@@ -365,7 +366,7 @@ For example, to receive a :class:`Member` you can just pass it as a converter:
@bot.command()
async def joined(ctx, *, member: discord.Member):
- await ctx.send('{0} joined on {0.joined_at}'.format(member))
+ await ctx.send(f'{member} joined on {member.joined_at}')
When this command is executed, it attempts to convert the string given into a :class:`Member` and then passes it as a
parameter for the function. This works by checking if the string is a mention, an ID, a nickname, a username + discriminator,
@@ -489,7 +490,7 @@ Consider the following example:
@bot.command()
async def bottles(ctx, amount: typing.Optional[int] = 99, *, liquid="beer"):
- await ctx.send('{} bottles of {} on the wall!'.format(amount, liquid))
+ await ctx.send(f'{amount} bottles of {liquid} on the wall!')
.. image:: /images/commands/optional1.png
@@ -515,7 +516,7 @@ Consider the following example:
@bot.command()
async def slap(ctx, members: commands.Greedy[discord.Member], *, reason='no reason'):
slapped = ", ".join(x.name for x in members)
- await ctx.send('{} just got slapped for {}'.format(slapped, reason))
+ await ctx.send(f'{slapped} just got slapped for {reason}')
When invoked, it allows for any number of members to be passed in:
@@ -586,8 +587,8 @@ handlers that allow us to do just that. First we decorate an error handler funct
@bot.command()
async def info(ctx, *, member: discord.Member):
"""Tells you some info about the member."""
- fmt = '{0} joined on {0.joined_at} and has {1} roles.'
- await ctx.send(fmt.format(member, len(member.roles)))
+ msg = f'{member} joined on {member.joined_at} and has {len(member.roles)} roles.'
+ await ctx.send(msg)
@info.error
async def info_error(ctx, error):
diff --git a/docs/ext/commands/extensions.rst b/docs/ext/commands/extensions.rst
index 10e33e45..3cb6d297 100644
--- a/docs/ext/commands/extensions.rst
+++ b/docs/ext/commands/extensions.rst
@@ -22,7 +22,7 @@ An example extension looks like this:
@commands.command()
async def hello(ctx):
- await ctx.send('Hello {0.display_name}.'.format(ctx.author))
+ await ctx.send(f'Hello {ctx.author.display_name}.')
def setup(bot):
bot.add_command(hello)