Build a guessing game: the bot picks a number between 1 and 100, members guess with /number guess, it answers higher or lower, and it announces who found it in how many tries
A number guessing game where the bot picks a random number between 1 and 100.
Commands:
/number new — Start a new game/number guess <number> — Make a guess (bot replies with "higher" or "lower")/number status — Check if a game is active and how many guesses you've madeWhen someone finds the number, the bot announces the winner and their attempt count. Optionally configure an announcement channel in settings to broadcast wins server-wide.
Made by MEE6. Remix it to get a copy of your own and change anything you like.
No active game. Use /number new to start one!
🎮 New game started! I've picked a number between 1 and 100. Use /number guess to try!
📈 Higher! (Attempt 1)
📉 Lower! (Attempt 2)
📉 Lower! (Attempt 1)
📉 Lower! (Attempt 3)
🎉 @Alex found it! The number was 52 in 4 tries!
❌ No active game! Use /number new to start one.
// Number Guessing Game: members guess a number between 1-100
mee6.settings({
announcement_channel: {
type: 'channel',
label: 'Announcement channel',
required: false,
sample: 'general',
},
});
// Start a new game
mee6.command('number new', { description: 'Start a new number guessing game' }, async (ctx) => {
const target = Math.floor(Math.random() * 100) + 1;
await mee6.store.set('game_active', true);
await mee6.store.set('game_target', target);
await mee6.store.set('game_starter', ctx.author.id);
// Clear all member guesses from previous game
const keys = await mee6.store.keys();
for (const key of keys) {
if (key.startsWith('guesses_')) {
await mee6.store.delete(key);
}
}
await ctx.reply("🎮 New game started! I've picked a number between 1 and 100. Use `/number guess` to try!");
});
// Make a guess
mee6.command(
'number guess',
{
description: 'Guess the number',
options: [
{
name: 'number',
type: 'integer',
description: 'Your guess (1-100)',
required: true,
},
],
},
async (ctx) => {
const guess = ctx.option<number>('number');
// Validate range
if (guess < 1 || guess > 100) {
await ctx.reply('❌ Please guess a number between 1 and 100.');
return;
}
// Check if game is active
const active = await mee6.store.get<boolean>('game_active');
if (!active) {
await ctx.reply('❌ No active game! Use `/number new` to start one.');
return;
}
const target = await mee6.store.get<number>('game_target');
if (target === null) {
await ctx.reply('❌ No active game! Use `/number new` to start one.');
return;
}
// Track this member's guess count
const m = mee6.store.member(ctx.author.id);
const guesses = await m.get<number>('guesses', 0);
await m.set('guesses', guesses + 1);
if (guess === target) {
// Winner!
await mee6.store.set('game_active', false);
const attempts = guesses + 1;
const message = `🎉 ${ctx.author.mention} found it! The number was **${target}** in **${attempts}** ${
attempts === 1 ? 'try' : 'tries'
}!`;
await ctx.reply(message);
// Also announce in configured channel if set
const channelId = ctx.settings.announcement_channel;
if (channelId && channelId !== ctx.channelId) {
await ctx.send(channelId, message);
}
} else if (guess < target) {
await ctx.reply(`📈 Higher! (Attempt ${guesses + 1})`);
} else {
await ctx.reply(`📉 Lower! (Attempt ${guesses + 1})`);
}
}
);
// Check current game status
mee6.command('number status', { description: 'Check if a game is active' }, async (ctx) => {
const active = await mee6.store.get<boolean>('game_active');
if (!active) {
await ctx.reply('No active game. Use `/number new` to start one!');
return;
}
const m = mee6.store.member(ctx.author.id);
const guesses = await m.get<number>('guesses', 0);
await ctx.reply(
`🎮 Game is active! You've made ${guesses} ${
guesses === 1 ? 'guess' : 'guesses'
} so far. The number is between 1 and 100.`
);
});