【发布时间】:2022-12-13 00:37:54
【问题描述】:
所以我只是一个业余爱好者,正在制作一个简单的 discord 机器人,这里有一个命令,如您所见,它是“添加”。问题是,当我运行它时它很好,但是当“mes”为空时,我们得到了好的 ol:
“mes 是缺少的必需参数。”。
编码
@bot.command()
async def add(ctx, *, mes):
if not mes == '':
await ctx.send('Added *' + mes + '* to the list')
file1 = open('file1.txt', 'a')
c = mes.lower()
word = '\n' + c
file1.writelines(word)
file1.close()
else:
await ctx.send("Please enter a word to add")
我寻找有类似问题的人,但我所能找到的只是具有所需“mes”的代码,修复是 *mes,即 (ctx, *, mes)。我尝试了很多东西但无济于事而且我不知道这里出了什么问题所以我可以寻求帮助
【问题讨论】:
标签: python-3.x discord.py