Why am I getting discord.py AttributeError: 'str' object has no attribute 'trigger_typing'

Viewed 651

I can't figure out why the hell I am getting this error. Everything in the code looks good to me. Maybe it is due to the converters not working but my other commands are working properly.

   async def ship(self, ctx: commands.Context, user1: discord.Member = None, user2: discord.Member = None):
        if user1 is None or user2 is None:
            await ctx.send(embed=discord.Embed(
                description=f"please mention two persons or provide two image urls! try: `{self.GetPrefix(ctx)}ship @person1 @person2` or `{self.GetPrefix(ctx)}ship [img url1] [img url2]`",
                color=self.randomcolor()))
        else:
            await ctx.trigger_typing()

            r1 = requests.get(user1.avatar_url)
            with open("images/ship_avatar1.png", "wb") as f1:
                f1.write(r1.content)

            r2 = requests.get(user2.avatar_url)
            with open("images/ship_avatar2.png", "wb") as f2:
                f2.write(r2.content)

            await self.ship("images/ship_avatar1.png", "images/ship_avatar2.png", "images/ship.png")

            embed = discord.Embed()
            embed.set_image(url="attachment://ship.png")

            file = discord.File("images/ship.png", "ship.png")

            await ctx.send(embed=embed, file=file)

The error I am getting is:

Ignoring exception in on_command_error
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/runner/Mob/cogs/fun.py", line 397, in ship
    await self.ship("images/ship_avatar1.png", "images/ship_avatar2.png", "images/ship.png")
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 372, in __call__
    return await self.callback(self.cog, *args, **kwargs)
  File "/home/runner/Mob/cogs/fun.py", line 387, in ship
    await ctx.trigger_typing()
AttributeError: 'str' object has no attribute 'trigger_typing'

2 Answers

I assume this function is not in a class. Therefore, the self value became a Context class and the ctx value became an argument. The error you get is "AttributeError: 'str' object has no attribute 'trigger_typing'" it means that a str object doesn't have access to the function trigger_typing. Remove the self value from the async function will be a quick fix.

The "ship" function which is not a command is already defined in the same class which is being called in the "ship" command function. Renaming the function solved the problem.

Related