is
when comparing type
of two objects 23 @commands.command(name="pat", aliases=["pet"])
24 @commands.cooldown(rate=2, per=5, type=commands.BucketType.member)
25 async def pet(self, ctx, image: discord.Member = None):
26 if type(image) == discord.member.Member: 27 image = await image.avatar.read() # retrieve the image bytes
28 else:
29 image = await ctx.author.avatar.read()
It is recommended to use identity test
( is
) instead of equality test ( ==
) when you need to compare types of two objects.
if type(x) == str:
print(x)
if type(x) is str:
print(x)
# Alternatively,
if isinstance(x, str):
print(x)