mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-04 08:56:19 +00:00
Fix type errors in all examples
This commit is contained in:
@ -83,8 +83,14 @@ class ChannelOrMemberConverter(commands.Converter):
|
||||
raise commands.BadArgument(f'No Member or TextChannel could be converted from "{argument}"')
|
||||
|
||||
|
||||
# Make it so the converter is friendly to type checkers
|
||||
# The first parameter of typing.Annotated is the type we tell the type checker
|
||||
# The second parameter is what converter the library uses
|
||||
ChannelOrMember = typing.Annotated[typing.Union[discord.Member, discord.TextChannel], ChannelOrMemberConverter]
|
||||
|
||||
|
||||
@bot.command()
|
||||
async def notify(ctx: commands.Context, target: ChannelOrMemberConverter):
|
||||
async def notify(ctx: commands.Context, target: ChannelOrMember):
|
||||
# This command signature utilises the custom converter written above
|
||||
# What will happen during command invocation is that the `target` above will be passed to
|
||||
# the `argument` parameter of the `ChannelOrMemberConverter.convert` method and
|
||||
@ -118,8 +124,8 @@ async def multiply(ctx: commands.Context, number: int, maybe: bool):
|
||||
# See: https://discordpy.readthedocs.io/en/latest/ext/commands/commands.html#bool
|
||||
|
||||
if maybe is True:
|
||||
return await ctx.send(number * 2)
|
||||
await ctx.send(number * 5)
|
||||
return await ctx.send(str(number * 2))
|
||||
await ctx.send(str(number * 5))
|
||||
|
||||
|
||||
bot.run('token')
|
||||
|
Reference in New Issue
Block a user