Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Searching for bots

Chew edited this page Nov 10, 2018 · 2 revisions

So, you want to search for a bot.

Searching

First, define your DBL variable. I'm just gonna do

DBL = DBLRuby.new(api, id)

Next, we simply type DBL.search(args)

But woah, what are the arguments? Simple!

There are 5 arguments.

offset [Integer] Amount of bots to skip
search [String] A search string in the format of field: value field2: value2
sort [String] The field to sort by. Prefix with - to reverse the order
fields [String] A comma separated list of fields to show.

So, if you want to search for an HQ Trivia bot, you would type: DBL.search(search: 'HQ Trivia')

Responses

How do we handle responses? Simple. Let's go back to our DBL.search(search: 'HQ Trivia')

This will return a search result. Let's store it to results.

Now, with this, we can see how many bots there are with results.size, which returns the amount of bots, where results.count will return whatever the API told us. Whichever you think is more reliable, but usually they're the same.

To get all the results, simply type results.results, this will return an Array of Bots. Here, you can use it as if it were a normally instantiated Bot. For example, we want to see the first bot's name. So, we type results.results[0].username, which will return the username of the first bot in the search results.

But wait, if we're just getting the first bot, we can just type results.first, which will return the first result. It's the same as results.results[0].