Let members add characters to a wishlist with /wish, and ping everyone who wished for it when that character comes up in a roll
A wishlist that pings you
Made by MEE6. Remix it to get a copy of your own and change anything you like.
✅ Added Goku to your wishlist! (1 total)
✅ Added Goku to your wishlist! (1 total)
✅ Added Naruto to your wishlist! (1 total)
🔔 @You @Alex — Goku appeared!
🔔 @Jordan — Naruto has appeared!
✅ Pinged 1 member!
✅ Removed Naruto from your wishlist! (0 remaining)
// Character Wishlist: members save characters they want, get pinged when they roll
mee6.settings({
roll_channel: {
type: 'channel',
label: 'Roll announcement channel',
required: true,
sample: 'general',
},
});
// Storage:
// - member 'wishlist': the characters a member wants, as they typed them
// - member 'wish_<character>': 1 for each of them, so the members who want a
// character are found in one call (memberTop) rather than one per member
// - member 'wishes_indexed': whether those keys were written — a wishlist
// saved by the first version gets them when its owner next uses /wish or
// /wishlist
// - global 'wished': every character somebody wants, to spot them in the chat
// A member's storage holds 64 keys, one per character on the wishlist
const MAX_WISHES = 40;
// Character names fit in a key (64 characters, 'wish_' included)
const MAX_NAME = 50;
// Members pinged at once: a message holds 2000 characters
const MAX_PINGS = 60;
// Characters looked up per roll message: a run makes 50 calls at most
const MAX_SPOTTED = 5;
/** The member key saying a member wants this character. */
function wishKey(character: string): string {
return `wish_${character.toLowerCase()}`;
}
/** Make sure everything on a member's wishlist can be found by others. */
async function indexWishlist(userId: string, wishlist: string[]): Promise<void> {
const m = mee6.store.member(userId);
if (await m.get<boolean>('wishes_indexed', false)) return;
const indexed = wishlist.filter((c) => c.length <= MAX_NAME).slice(0, MAX_WISHES);
for (const character of indexed) await m.set(wishKey(character), 1);
await addWished(indexed);
await m.set('wishes_indexed', true);
}
/** Add characters to the server's list of wished-for characters. */
async function addWished(characters: string[]): Promise<void> {
const wished = await mee6.store.get<string[]>('wished', []);
const known = new Set(wished.map((c) => c.toLowerCase()));
const added = characters.filter((c) => !known.has(c.toLowerCase()));
if (added.length) await mee6.store.set('wished', [...wished, ...added]);
}
/** The members who want a character, as mentions. */
async function wishers(character: string, limit: number): Promise<string[]> {
const top = await mee6.store.memberTop(wishKey(character), limit);
return top.map((entry) => `<@${entry.userId}>`);
}
// Add a character to your wishlist
mee6.command(
'wish',
{
description: 'Add a character to your wishlist',
options: [{ name: 'character', type: 'string', description: 'Character name', required: true }],
},
async (ctx) => {
const character = ctx.option<string>('character').trim();
if (!character) {
await ctx.reply('Please provide a character name.');
return;
}
if (character.length > MAX_NAME) {
await ctx.reply(`Character names are ${MAX_NAME} characters at most.`);
return;
}
const m = mee6.store.member(ctx.author.id);
const wishlist = await m.get<string[]>('wishlist', []);
await indexWishlist(ctx.author.id, wishlist);
if (wishlist.length >= MAX_WISHES) {
await ctx.reply(`Your wishlist is full (${MAX_WISHES} characters) — \`/unwish\` one first.`);
return;
}
// Normalize for comparison (case-insensitive)
const normalized = character.toLowerCase();
if (wishlist.some((c) => c.toLowerCase() === normalized)) {
await ctx.reply(`**${character}** is already on your wishlist!`);
return;
}
wishlist.push(character);
await m.set('wishlist', wishlist);
await m.set(wishKey(character), 1);
await addWished([character]);
await ctx.reply(`✅ Added **${character}** to your wishlist! (${wishlist.length} total)`);
}
);
// Remove a character from your wishlist
mee6.command(
'unwish',
{
description: 'Remove a character from your wishlist',
options: [{ name: 'character', type: 'string', description: 'Character name', required: true }],
},
async (ctx) => {
const character = ctx.option<string>('character').trim();
const m = mee6.store.member(ctx.author.id);
const wishlist = await m.get<string[]>('wishlist', []);
const normalized = character.toLowerCase();
const index = wishlist.findIndex((c) => c.toLowerCase() === normalized);
if (index === -1) {
await ctx.reply(`**${character}** is not on your wishlist.`);
return;
}
const [removed] = wishlist.splice(index, 1);
await m.set('wishlist', wishlist);
await m.delete(wishKey(removed));
// Nobody wants it any more: the chat no longer needs watching for it
if ((await mee6.store.memberTop(wishKey(removed), 1)).length === 0) {
const wished = await mee6.store.get<string[]>('wished', []);
await mee6.store.set(
'wished',
wished.filter((c) => c.toLowerCase() !== removed.toLowerCase())
);
}
await ctx.reply(`✅ Removed **${character}** from your wishlist! (${wishlist.length} remaining)`);
}
);
// View your wishlist
mee6.command('wishlist', { description: 'View your wishlist' }, async (ctx) => {
const m = mee6.store.member(ctx.author.id);
const wishlist = await m.get<string[]>('wishlist', []);
await indexWishlist(ctx.author.id, wishlist);
if (wishlist.length === 0) {
await ctx.reply('Your wishlist is empty! Use `/wish <character>` to add characters.');
return;
}
await ctx.reply({
embed: {
title: '📝 Your Wishlist',
description: wishlist.map((c, i) => `${i + 1}. ${c}`).join('\n'),
color: '#5865F2',
footer: { text: `${wishlist.length} character${wishlist.length === 1 ? '' : 's'}` },
},
});
});
// Trigger: detect rolls in messages and ping wishlist members
// Only messages in the configured roll channel wake the module, and only the
// ones with a common roll bot keyword ("rolled", "claim", "spawned"…) — a simple
// detection pattern you can customize
const ROLL_KEYWORDS = ['roll', 'claim', 'spawn'];
mee6.on('message', { channels: [mee6.setting('roll_channel')], contains: ROLL_KEYWORDS }, async (ctx) => {
const content = ctx.message.content.toLowerCase();
// The characters somebody wants that this message names
const wished = await mee6.store.get<string[]>('wished', []);
const spotted = wished.filter((c) => content.includes(c.toLowerCase())).slice(0, MAX_SPOTTED);
if (spotted.length === 0) return;
// Each member pinged once, however many of their characters appeared
const mentions = new Set<string>();
const matches: string[] = [];
for (const character of spotted) {
const found = await wishers(character, MAX_PINGS);
if (found.length) matches.push(character);
for (const mention of found) mentions.add(mention);
}
// If we found matches, ping the users
if (mentions.size > 0) {
await ctx.send(ctx.channelId, {
content: `🔔 ${[...mentions].slice(0, MAX_PINGS).join(' ')} — **${matches.join(', ')}** appeared!`,
});
}
});
// Admin command: announce a character roll manually
mee6.command(
'announce',
{
description: 'Announce a character roll and ping wishlist members',
options: [{ name: 'character', type: 'string', description: 'Character name', required: true }],
},
async (ctx) => {
const character = ctx.option<string>('character').trim();
const rollChannel = ctx.settings.roll_channel;
if (!rollChannel) {
await ctx.reply('Roll channel not configured. Ask an admin to set it in the dashboard.');
return;
}
// Find the members who have this character on their wishlist
const mentions = character.length > MAX_NAME ? [] : await wishers(character, MAX_PINGS);
if (mentions.length === 0) {
await ctx.reply(`No one has **${character}** on their wishlist.`);
return;
}
await ctx.send(rollChannel, {
content: `🔔 ${mentions.join(' ')} — **${character}** has appeared!`,
});
await ctx.reply(`✅ Pinged ${mentions.length} member${mentions.length === 1 ? '' : 's'}!`, {
ephemeral: true,
});
}
);