This snippet will send a reply to the last message sent in a channel. The reply will contain a random custom emoji! Note: You can change the schedule of the auto-reply in the endpoint trigger.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const CHANNEL_ID = `CHANNEL_ID`; //Channel ID where emoji will be sent
const GUILD_ID = `GUILD_ID`; //Guild or Server ID
let result = await lib.discord.guilds['@0.2.4'].emojis.list({
guild_id: `${GUILD_ID}`,
});
let emoji = result[Math.floor(Math.random() * result.length)];
let emojiBuilder = `<`;
emojiBuilder += emoji.animated ? `a:` : `:`;
emojiBuilder += `${emoji.name}:${emoji.id}>`;
let lastMessage = await lib.discord.channels['@0.3.2'].messages.list({
channel_id: `${CHANNEL_ID}`,
limit: 1,
});
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${CHANNEL_ID}`,
content: `${emojiBuilder}`,
message_reference: {
message_id: `${lastMessage[0].id}`,
},
});