Allows you to run !enable and !disable to change whether your command is enabled. Change !yourcommand in the code to your actual prefix command and put logic in the proper if statement.
// authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let key = `__enableCommandFlag__`;
if (context.params.event.content === '!enable') {
await lib.utils.kv.set({
key: key,
value: true
});
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Command enabled!`
});
} else if (context.params.event.content === '!disable') {
await lib.utils.kv.clear({
key: key
});
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Command disabled!`
});
} else if (context.params.event.content.startsWith('!yourcommand')) {
let isEnabled = await lib.utils.kv.get({
key: key
});
if (isEnabled) {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `The command is enabled! It is doing things!`
});
} else {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Sorry, you need to run !enable before using this command.`
});
}
}