Python pymongo find_one在discord.py命令中使用时不会重新运行None,但在终端中工作正常
这是我在收藏中搜索的文档Python pymongo find_one在discord.py命令中使用时不会重新运行None,但在终端中工作正常,python,python-3.x,mongodb,discord.py,pymongo,Python,Python 3.x,Mongodb,Discord.py,Pymongo,这是我在收藏中搜索的文档 {'_id': ObjectId('5fef0220e37ad50a37582bc1'), 'nationid': 176311, 'nation': 'Markovia', 'leader': 'Sam Cooper', 'continent': 'Africa', 'war_policy': 'Pirate', 'color': 'beige', 'alliance': 'Arrgh', 'allianceid': 913, 'allianceposition':
{'_id': ObjectId('5fef0220e37ad50a37582bc1'), 'nationid': 176311, 'nation': 'Markovia', 'leader': 'Sam Cooper', 'continent': 'Africa', 'war_policy': 'Pirate', 'color': 'beige', 'alliance': 'Arrgh', 'allianceid': 913, 'allianceposition': 3, 'cities': 19, 'infrastructure': 11400, 'offensivewars': 0, 'defensivewars':
0, 'score': 2283.09, 'rank': 10, 'vacmode': 0, 'minutessinceactive': 50, 'query_nation': 'markovia', 'query_leader': 'sam cooper'}
我有一个功能,可以使用“国家ID”
、“查询国家”
或“查询领导人”
进行搜索:
当我搜索176311
和markovia
时,该命令工作正常,但sam cooper
@client.command()
async def nation(ctx, nation):
nation_dict_1 = find_nation(nation)
if nation_dict_1:
await ctx.send(f'{nation_dict_1["leader"]} of {nation_dict_1["nation"]}')
else:
await ctx.send('Could not find an exact match.')
然而,当我在终端中使用它时,它可以很好地处理所有3个,并且每次都打印文档。(也与sam cooper一起使用)
这是一个如何将参数传递到命令的问题<代码> sam cooper <代码>由于中间的空间不能工作。要解决这个问题,可以使用星号的“使用rest”功能 请尝试以下操作,重新编写的命令:
@client.command()
async def nation(ctx, *, nation):
nation_dict_1 = find_nation(nation)
if nation_dict_1:
await ctx.send(f'{nation_dict_1["leader"]} of {nation_dict_1["nation"]}')
else:
await ctx.send('Could not find an exact match.')
如果您这样做,当前命令将起作用:!国家“山姆库珀”
但使用星号将允许您输入不带引号的参数
参考资料:
@client.command()
async def nation(ctx, *, nation):
nation_dict_1 = find_nation(nation)
if nation_dict_1:
await ctx.send(f'{nation_dict_1["leader"]} of {nation_dict_1["nation"]}')
else:
await ctx.send('Could not find an exact match.')
如果您这样做,当前命令将起作用:!国家“山姆库珀”
但使用星号将允许您输入不带引号的参数
参考资料:
@client.command()
async def nation(ctx, *, nation):
nation_dict_1 = find_nation(nation)
if nation_dict_1:
await ctx.send(f'{nation_dict_1["leader"]} of {nation_dict_1["nation"]}')
else:
await ctx.send('Could not find an exact match.')