Keep a sticky message at the bottom of a channel I choose: every time five messages are posted there, delete the previous sticky and post it again, with /sticky set to change its text
Sticky Message keeps a chosen message at the bottom of a channel by automatically reposting it after every 5 messages.
/sticky set and type the text you want to keep at the bottom/sticky set)Perfect for channel rules, important announcements, or information you want members to always see!
Made by MEE6. Remix it to get a copy of your own and change anything you like.
โ Sticky message updated!
๐ Welcome to #general! Please read the rules before posting.
// Sticky Message: keeps a message at the bottom of a channel by reposting after every 5 messages
mee6.settings({
sticky_channel: {
type: 'channel',
label: 'Channel for sticky message',
required: true,
sample: 'general',
},
sticky_text: {
type: 'string',
label: 'Sticky message text',
default: '๐ This message stays at the bottom!',
sample: '๐ This message stays at the bottom!',
},
});
mee6.command(
'sticky set',
{
description: 'Set the sticky message text',
options: [{ name: 'text', type: 'string', description: 'The message to keep sticky', required: true }],
},
async (ctx) => {
const text = ctx.option<string>('text');
// Update the sticky text in storage
await mee6.store.set('sticky_text', text);
// Delete the old sticky if it exists
const oldMessageId = await mee6.store.get<string>('sticky_message_id');
if (oldMessageId) {
try {
await mee6.deleteMessage(ctx.settings.sticky_channel, oldMessageId);
} catch (e) {
// Message might already be deleted
}
}
// Post the new sticky
const sent = await ctx.send(ctx.settings.sticky_channel, text);
await mee6.store.set('sticky_message_id', sent.messageId);
await mee6.store.set('message_count', 0);
await ctx.reply({ content: 'โ
Sticky message updated!', ephemeral: true });
}
);
// Only messages in the sticky channel wake the module
mee6.on('message', { channels: [mee6.setting('sticky_channel')] }, async (ctx) => {
// Don't count the bot's own messages
if (ctx.author.bot) return;
// Get current count and increment
const count = await mee6.store.incr('message_count', 1);
// Every 5 messages, repost the sticky
if (count >= 5) {
const text = (await mee6.store.get<string>('sticky_text')) || ctx.settings.sticky_text;
const oldMessageId = await mee6.store.get<string>('sticky_message_id');
// Delete the old sticky
if (oldMessageId) {
try {
await mee6.deleteMessage(ctx.channelId, oldMessageId);
} catch (e) {
// Message might already be deleted
}
}
// Post the new sticky
const sent = await ctx.send(ctx.channelId, text);
await mee6.store.set('sticky_message_id', sent.messageId);
await mee6.store.set('message_count', 0);
}
});