【发布时间】: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