@commands.command(aliases=['lookup'])
async def define(self, message, *, arg):
dictionary=PyDictionary()
Define = dictionary.meaning(arg)
length = len(arg.split())
if length == 1:
embed = discord.Embed(description="**Noun:** " + Define["Noun"][0] + "\n\n**Verb:** " + Define["Verb"][0], color=0x00ff00)
embed.set_author(name = ('Defenition of the word: ' + arg),
icon_url=message.author.avatar_url)
await message.send(embed=embed)
else:
CommandError = discord.Embed(description= "A Term must be only a single word" , color=0xfc0328)
await message.channel.send(embed=CommandError)
我想做检查是否Noun
and Verb
字典里有Define
,因为当一个单词在其定义中只包含一个名词时,它会抛出一个错误,因为我试图用机器人输出名词和动词,看看我得到了什么。我是字典新手,非常感谢任何帮助
您可以使用以下代码测试密钥是否存在:
if key_to_test in dict.keys():
print("The key exists")
else:
print("The key doesn't exist")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)