Skip to content

Instantly share code, notes, and snippets.

@YorkAARGH
YorkAARGH / example.js
Created April 4, 2018 20:31
Highcharts-Example
const Chart = require('./Chart');
module.exports = class extends Chart {
constructor(stats, dashStats) {
super();
const now = new Date();
this.options.title.text = 'Usage Stats';
this.options.plotOptions.series.pointStart = now.setHours(now.getHours() - 1);
this.options.plotOptions.series.pointInterval = 60 * 1000;
@YorkAARGH
YorkAARGH / structure.js
Created April 4, 2018 20:30
Highcharts-Structure
const exporter = require('highcharts-export-server');
const { promisify } = require('util');
const { writeFile } = require('fs-nextra');
const render = promisify(exporter.export);
exporter.initPool();
module.exports = class Chart {
constructor() {
this.type = 'png';

Using Discord Webhooks

In the last chapter we covered how to create the webhooks via code, which to be honest isn't very useful, in this chapter we will continue where we left off and we will actually use the webhooks we create in some bot code.

Now, one way we could use this, is to grab mentions... For some reason people think it's acceptable to mention me then shortly afterwards remove the mention if I don't respond within X seconds or minutes.

We have two choices, either create a stand-alone bot, or throw it in an existing bot... For the purposes of this guide I will throw the code in a stand alone bot, but it should be pretty self-explanatory how to add this to an existing bot.

NOTE USE AT YOUR OWN RISK. Even though selfbots are not allowed to react to anything other than the account owner, I believe this is perfectly acceptable if it doesn't react in a public fashion, having a PRIVATE channel would be acceptable in my opinion.

@YorkAARGH
YorkAARGH / app.js
Last active January 25, 2018 00:30
Simple, complete example of a bot in Discord.js
// Load up the discord.js library
const Discord = require("discord.js");
// This is your client. Some people call it `bot`, some people call it `self`,
// some might call it `cootchie`. Either way, when you see `client.something`, or `bot.something`,
// this is what we're refering to. Your client.
const client = new Discord.Client();
// Here we load the config.json file that contains our token and our prefix values.
const config = require("./config.json");

Alright, I'm trying to pass the client to the guildDelete event, I've got this inside my eventLoader.js file.

const reqEvent = (event) => require(`../events/${event}`);
module.exports = client => {
  client.on('guildDelete', (...args) => reqEvent('guildDelete')(client, ...args));
};

And this is in my guildDelete.js event file.

const dataP = require('../functions/dataProvider.js');
const Discord = require('discord.js');
exports.run = (client, message) => {
const embed = new Discord.RichEmbed()
.setAuthor(message.guild.name, message.guild.iconURL)
.setColor(3447003)
.setDescription(`Owner: ${message.guild.owner.user.tag} (${message.guild.owner.id})`)
.addField('Member Count', `${message.guild.memberCount - message.guild.members.filter(m=>m.user.bot).size} (${message.guild.members.filter(m=>m.user.bot).size} bots)`, true)
.addField('AFK Timeout', `${message.guild.afkTimeout / 60} minutes`, true)
.addField('AFK Channel', `${message.guild.afkChannelID === null ? 'No AFK Channel' : client.channels.get(message.guild.afkChannelID).name} (${message.guild.afkChannelID === null ? '' : message.guild.afkChannelID})`, true)
.addField('Location', message.guild.region, true)

Argument Usage in Komada

Usage Structure

<> required argument, [] optional argument <Name:Type{min,max}>

  • Name Mostly used for debugging message, unless the type is Litteral in which it compares the argument to the name.
  • Type The type of variable you are expecting
  • Min, Max Minimum or Maximum for a giving variable (works on strings in terms of length, and on all types of numbers in terms of value) You are allowed to define any combination of min and max. Omit for none, {min} for min, {,max} for max.
  • Special Repeat Tag [...] will repeat the last usage optionally until you run out of arguments. Useful for doing something like <SearchTerm:str> [...] which will allow you to take as many search terms as you want, per your Usage Deliminator.