Create and Destroy invites for a channel or guild. How to use guide is on lines 4-10
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
/*
How to use:
Use !invite to get a help menu
use !invite create to create an invite
use !invite destroy all to destroy all invites in a guild
use !invite destroy channel to destroy all invites in a channel
*/
let choice = context.params.event.content.split(' ')[1];
if (choice === `create`) {
let invite = await lib.discord.invites['@0.1.0'].create({
channel_id: context.params.event.channel_id,
max_age: 0,
max_uses: 0,
temporary: false,
unique: false,
target_type: 'GUILD',
});
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: context.params.event.channel_id,
content: ``,
embeds: [
{
title: `Invite Created`,
description: `**Link:** https://discord.gg/${invite.code}`,
color: 0x57f287,
},
],
});
} else if (choice === `destroy`) {
choice = context.params.event.content.split(' ')[2];
if (choice === `all`) {
let invites = await lib.discord.guilds['@0.2.3'].invites.list({
guild_id: context.params.event.guild_id,
});
for (let i = 0; i < invites.length; i++) {
await lib.discord.invites['@0.1.0'].destroy({
invite_code: invites[i].code,
});
}
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: context.params.event.channel_id,
content: ``,
embeds: [
{
title: `Invites Destroyed`,
description: `All invites in this server have been destroyed`,
color: 0x57f287,
},
],
});
} else if (choice === `channel`) {
let invites = await lib.discord.channels['@0.3.1'].invites.list({
channel_id: context.params.event.channel_id,
});
for (let i = 0; i < invites.length; i++) {
await lib.discord.invites['@0.1.0'].destroy({
invite_code: invites[i].code,
});
}
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: context.params.event.channel_id,
content: ``,
embeds: [
{
title: `Invites Destroyed`,
description: `All invites in <#${context.params.event.channel_id}> have been destroyed`,
color: 0x57f287,
},
],
});
}
} else if (!choice) {
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: context.params.event.channel_id,
content: ``,
embeds: [
{
title: `Provide a method!`,
description: `**Methods:**\n\n\`create\` - Create an invite in the current channel\n\`destroy all\` - Destroy all invites in a guild\n\`destroy channel\` - Destroy all invites in the current channel\n\n*(destroying invites may take multiple trys due to Discord rate limiting)*`,
color: 0xed4245,
},
],
});
}