程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么我得到 discord.py AttributeError: 'str' object has no attribute 'trigger_typing'大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决为什么我得到 discord.py AttributeError: 'str' object has no attribute 'trigger_typing'?

开发过程中遇到为什么我得到 discord.py AttributeError: 'str' object has no attribute 'trigger_typing'的问题如何解决?下面主要结合日常开发的经验,给出你关于为什么我得到 discord.py AttributeError: 'str' object has no attribute 'trigger_typing'的解决方法建议,希望对你解决为什么我得到 discord.py AttributeError: 'str' object has no attribute 'trigger_typing'有所启发或帮助;

我不明白为什么我会收到这个错误。代码中的所有内容对我来说都很好。也许是因为转换器不工作,但我的其他命令工作正常。

   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)

我得到的错误是:

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.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,line 387,in ship
    await ctx.trigger_tyPing()
AttributeError: 'str' object has no attribute 'trigger_tyPing'

解决方法

我假设这个函数不在一个类中。因此,self 值变成了一个 Context 类,而 ctx 值变成了一个参数。您得到的错误是“AttributeError: 'str' object has no attribute 'trigger_typing'”,这意味着 str 对象无权访问函数 trigger_typing。从异步函数中删除 self 值将是一个快速修复。

,

不是命令的“ship”函数已经在“ship”命令函数中调用的同一个类中定义。重命名函数解决了问题。

大佬总结

以上是大佬教程为你收集整理的为什么我得到 discord.py AttributeError: 'str' object has no attribute 'trigger_typing'全部内容,希望文章能够帮你解决为什么我得到 discord.py AttributeError: 'str' object has no attribute 'trigger_typing'所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。