【问题标题】:AttributeError: 'tuple' object has no attribute 'replace', error with owotext libraryAttributeError:“元组”对象没有“替换”属性,owotext 库出错
【发布时间】:2021-07-07 00:19:49
【问题描述】:

所以我正在开发一个 Discord 机器人,并且我正在尝试制作一个“owoizes”文本的命令, 我决定使用“owotext”库,因为它最适合我正在尝试做的事情。

这是我的代码:

from owotext import OwO
uwu = OwO([''], [' >w<','...',' uwu'], {'r': 'w','l':'w', 'name': 'naem', 'oo': 'ooo','thi': 'di','oo': 'ooo', 'ow': 'owo','one': 'wun','wan': 'wun'})

@bot.command(aliases = ['owoify'])
async def  owo(ctx, *words):
    a=(f'{words[0]}-{uwu.whatsthis(words)}')
    a = await ctx.send(a)
    print(f"{author} run command owo in the server {name}({guild}) at {x}")

返回此错误:

Ignoring exception in command owo:
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\discordbot.py", line 432, in owo
    a=(f'{words[0]}-{uwu.whatsthis(words)}')
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\owotext\owo.py", line 87, in whatsthis
    text = self.translate(text)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\owotext\owo.py", line 102, in translate
    text = text.replace(key, value)
AttributeError: 'tuple' object has no attribute 'replace'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'tuple' object has no attribute 'replace'

我用错误代码查看了整个谷歌,但我只能找到人 尝试直接使用“替换”而不是通过库。

这里是 owotext 库文档: OwOText Documentation

【问题讨论】:

  • 从“文档”看来,“whatsthis”需要一个字符串,但你给它一个元组。
  • 谢谢,我只是将元组转换为用空格分隔的字符串。
  • 此更新代码:``` @bot.command(aliases = ['owoify']) async def owo(ctx, *words): " ".join(words) a=(f' {words[0]}-{uwu.whatsthis(words)}') a = await ctx.send(a) ``` 返回同样的错误...
  • 没关系,我用这个修复了它:words = str(" ".join(words))

标签: python python-3.x discord discord.py


【解决方案1】:
@bot.command(aliases = ['owoify']) 
async def owo(ctx, *words): 
    words = str(" ".join(words)) 
    a=(f'{words[0]}-{uwu.whatsthis(words)}') 
    a = await ctx.send(a)

【讨论】:

    猜你喜欢
    • 2020-03-23
    • 1970-01-01
    • 2013-06-21
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    相关资源
    最近更新 更多