diff options
| author | Rapptz <[email protected]> | 2021-04-04 04:40:19 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-04-04 07:03:53 -0400 |
| commit | 9d39b135f4f84239787b0901d06a4f370a82d4bb (patch) | |
| tree | 8826845cfd47eafa5c9d2ef1fcbedd36382714f4 /examples/converters.py | |
| parent | Bump minimum Python version to 3.8 (diff) | |
| download | discord.py-9d39b135f4f84239787b0901d06a4f370a82d4bb.tar.xz discord.py-9d39b135f4f84239787b0901d06a4f370a82d4bb.zip | |
Modernize code to use f-strings
This also removes the encoding on the top, since Python 3 does it by
default. It also changes some methods to use `yield from`.
Diffstat (limited to 'examples/converters.py')
| -rw-r--r-- | examples/converters.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/examples/converters.py b/examples/converters.py index 74b9c3c4..41aba498 100644 --- a/examples/converters.py +++ b/examples/converters.py @@ -29,7 +29,7 @@ async def userinfo(ctx: commands.Context, user: discord.User): user_id = user.id username = user.name avatar = user.avatar_url - await ctx.send('User found: {} -- {}\n{}'.format(user_id, username, avatar)) + await ctx.send(f'User found: {user_id} -- {username}\n{avatar}') @userinfo.error async def userinfo_error(ctx: commands.Context, error: commands.CommandError): @@ -70,7 +70,7 @@ class ChannelOrMemberConverter(commands.Converter): # If the value could not be converted we can raise an error # so our error handlers can deal with it in one place. # The error has to be CommandError derived, so BadArgument works fine here. - raise commands.BadArgument('No Member or TextChannel could be converted from "{}"'.format(argument)) + raise commands.BadArgument(f'No Member or TextChannel could be converted from "{argument}"') @@ -81,7 +81,7 @@ async def notify(ctx: commands.Context, target: ChannelOrMemberConverter): # the `argument` parameter of the `ChannelOrMemberConverter.convert` method and # the conversion will go through the process defined there. - await target.send('Hello, {}!'.format(target.name)) + await target.send(f'Hello, {target.name}!') @bot.command() async def ignore(ctx: commands.Context, target: typing.Union[discord.Member, discord.TextChannel]): @@ -95,9 +95,9 @@ async def ignore(ctx: commands.Context, target: typing.Union[discord.Member, dis # To check the resulting type, `isinstance` is used if isinstance(target, discord.Member): - await ctx.send('Member found: {}, adding them to the ignore list.'.format(target.mention)) + await ctx.send(f'Member found: {target.mention}, adding them to the ignore list.') elif isinstance(target, discord.TextChannel): # this could be an `else` but for completeness' sake. - await ctx.send('Channel found: {}, adding it to the ignore list.'.format(target.mention)) + await ctx.send(f'Channel found: {target.mention}, adding it to the ignore list.') # Built-in type converters. @bot.command() |