This snippet will generate a guild invitation link that is placed in a customizable embed. To invoke, user shall simply enter the prefix (eg .invite).
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let expiration = 0; // in seconds (e.g 1800 for 30 minutes; if you want no expiry, set to 0)
let maxUsage = 0; // number of usage (e.g 1 for one-time use only; if you want unlimited usage, set to 0)
let invite = await lib.discord.invites['@0.1.0'].create({
channel_id: `${context.params.event.channel_id}`,
max_age: expiration ,
max_uses: maxUsage,
temporary: false,
unique: false,
target_type: 'GUILD',
});
let inviteCode = invite.code;
let url = `https://discord.gg/${inviteCode}`;
let description = 'The invite url is: [' + url +
'](https://' + url + `)\n\n\n`;
let guild = await lib.discord.guilds['@0.2.4'].retrieve({
guild_id: context.params.event.guild_id,
});
// Here is the Embed where you can update it according to your needs, take note of the comment below
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ``,
embeds: [
{
type: 'rich',
title: `${guild.name}`,
description: `${description}`, // you can add anything here, but do not delete the ${description} as this is the invite link
thumbnail: {
url: `${guild.icon_url}`,
height: 0,
width: 0,
},
footer: {
text: `Invited by ${context.params.event.author.username}`,
icon_url: `https://cdn.discordapp.com/avatars/${context.params.event.author.id}/${context.params.event.author.avatar}`,
},
},
],
});