Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm currently making an "info [argument]" command for discord.py bot that will search and return a value

So the user would say: "!Info bookshelf" the bot would look up "bookshelf" in the JSON file and find bookshelf = Shelf full of books and pull the value describing the bookshelf and send it in chat.

I'm new to coding so this would help so much! Thank you in advance <3

working on Python 3.9

question from:https://stackoverflow.com/questions/65713107/how-can-i-search-a-json-file-with-given-argument-with-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
124 views
Welcome To Ask or Share your Answers For Others

1 Answer

Quite a simple solution: You would just take the arguments from the command (in this case "bookcase"), then parse it in to a search.

def lookup(args):
    look = data[args]
    return look

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...