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

Automatically update your bot's server count

Chew edited this page Apr 22, 2018 · 3 revisions

So, you want to easily update the bot's server count? Look no further!

The method #stats.updateservercount will easily update your bot's server count!

Example

Take this, a properly instantiated bot program and DBL.

# Load ruby gems
require 'dblruby'
require 'discordrb'
require 'yaml'

# Load config from file
CONFIG = YAML.load_file('config.yaml')

# Instantiate DBL
DBL = DBLRuby.new(CONFIG['dbotsorg'], CONFIG['client_id'])

# Instantiate Bot
bot = Discordrb::Commands::CommandBot.new token: CONFIG['token'], client_id: CONFIG['client_id']

# Listen to server joins
bot.server_create do |event|
  DBL.stats.updateservercount(event.bot.servers.count)
end

# Listen to server deletes/leaves
bot.server_delete do |event|
  DBL.stats.updateservercount(event.bot.servers.count)
end

# Run
bot.run

Where CONFIG stores data.

You're welcome.

Clone this wiki locally