나는 PyMongo를 사용하여 discord.py로 기본 통화 봇을 만들고 있지만 사용자는 db에 여러 번 등록 할 수 있습니다.
async def register(ctx):
insert = {"userid":ctx.message.author.id,"cash":0}
collection.insert_one(insert)
await ctx.send('okie dokie you are registered')
이것은 register 명령의 코드이지만 collection.find 쿼리가 true 또는 false를 반환하는지 확인하는 방법을 모르겠습니다. 아무도 그것을 수표로 사용하는 방법을 알고 있거나 이미 등록되어 있는지 확인하는 방법을 알고 있습니까?
find_one()
obj를 반환하거나 None을 사용할 수 있습니다 .
async def register(ctx):
existing = collection.find_one({"userid": ctx.author.id})
if not existing:
# register the user
else:
await ctx.send("Sorry, you're already registered.")
참조 :
collection.find_one()
- "단일 문서를 반환하거나 None
일치하는 문서가없는 경우"라고 표시됩니다.이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다