Browse Source

Use f-strings in more places that were missed

pull/6682/head
Sebastian Law 4 years ago
committed by GitHub
parent
commit
05c123f3ab
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      docs/ext/commands/api.rst
  2. 6
      docs/ext/commands/cogs.rst
  3. 17
      docs/ext/commands/commands.rst
  4. 2
      docs/ext/commands/extensions.rst
  5. 4
      docs/faq.rst
  6. 4
      docs/intro.rst
  7. 2
      docs/quickstart.rst

2
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``\.

6
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:

17
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):

2
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)

4
docs/faq.rst

@ -388,7 +388,7 @@ Example: ::
@bot.command()
async def length(ctx):
await ctx.send('Your message is {} characters long.'.format(len(ctx.message.content)))
await ctx.send(f'Your message is {len(ctx.message.content)} characters long.')
How do I make a subcommand?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -405,6 +405,6 @@ Example: ::
@git.command()
async def push(ctx, remote: str, branch: str):
await ctx.send('Pushing to {} {}'.format(remote, branch))
await ctx.send(f'Pushing to {remote} {branch}')
This could then be used as ``?git push origin master``.

4
docs/intro.rst

@ -102,10 +102,10 @@ A quick example to showcase how events work:
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
print(f'Logged on as {self.user}!')
async def on_message(self, message):
print('Message from {0.author}: {0.content}'.format(message))
print(f'Message from {messsage.author}: {message.content}')
client = MyClient()
client.run('my token goes here')

2
docs/quickstart.rst

@ -23,7 +23,7 @@ It looks something like this:
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):

Loading…
Cancel
Save