Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Return only a number.#499

Answeredbymsiemens
Brncray asked this question inQ&A
Jan 8, 2023· 1 comments· 3 replies
Discussion options

I am using this for an economy bot on discord. How would I return only a number?
results = db.search(User.id == ctx.options.member) if results == []: await ctx.respond("User doesn't exist... adding to database.") db.insert({"id": ctx.options.member, "bal": 0}) else: await ctx.respond(results)
image

I want to only return the name and the balance, take away the brackets.

You must be logged in to vote

Would something like this fork for you?

results=db.search(User.id==ctx.options.member)ifresults== []:awaitctx.respond("User doesn't exist... adding to database.")db.insert({"id":ctx.options.member,"bal":0})else:awaitctx.respond(results[0].bal)

Replies: 1 comment 3 replies

Comment options

Would something like this fork for you?

results=db.search(User.id==ctx.options.member)ifresults== []:awaitctx.respond("User doesn't exist... adding to database.")db.insert({"id":ctx.options.member,"bal":0})else:awaitctx.respond(results[0].bal)
You must be logged in to vote
3 replies
@Brncray
Comment options

I got the error,AttributeError: 'Document' object has no attribute 'bal'.

@msiemens
Comment options

Ah, that's my fault. Try this instead:

results=db.search(User.id==ctx.options.member)ifresults== []:awaitctx.respond("User doesn't exist... adding to database.")db.insert({"id":ctx.options.member,"bal":0})else:awaitctx.respond(results[0]['bal'])
@Brncray
Comment options

This worked, thank you :)

Answer selected byBrncray
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@Brncray@msiemens

[8]ページ先頭

©2009-2025 Movatter.jp