sendDice
Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.
Parameters
business_connection_idStringOptionalUnique identifier of the business connection on behalf of which the message will be sent
chat_idIntegerStringRequiredUnique identifier for the target chat or username of the target channel (in the format
@channelusername)message_thread_idIntegerOptionalUnique identifier for the target message thread (topic) of a forum; for forum supergroups and private chats of bots with forum topic mode enabled only
direct_messages_topic_idIntegerOptionalIdentifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat
emojiStringOptional Default: 🎲Values:
🎲🎯🏀⚽🎳🎰disable_notificationBooleanOptionalSends the message silently. Users will receive a notification with no sound.
protect_contentBooleanOptionalProtects the contents of the sent message from forwarding
allow_paid_broadcastBooleanOptionalPass True to allow up to 1000 messages per second, ignoring broadcasting limits for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance
message_effect_idStringOptionalUnique identifier of the message effect to be added to the message; for private chats only
A JSON-serialized object containing the parameters of the suggested post to send; for direct messages chats only. If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
Description of the message to reply to
reply_markupInlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReplyOptional⌨️ KeyboardsAdditional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user
Returns
On success, the Message object is returned.
GramIO Usage
Send a default dice (🎲) and read its rolled value:
ts
bot.on("message", async (ctx) => {
const msg = await ctx.sendDice("🎲");
const rolled = msg.dice?.value ?? 0;
await ctx.send(`You rolled a ${rolled}!`);
});Reply to the user's message with a dice throw:
ts
bot.on("message", async (ctx) => {
const msg = await ctx.replyWithDice("🎲");
const rolled = msg.dice?.value ?? 0;
await ctx.send(`You rolled: ${rolled}`);
});Send a slot machine (🎰) and check for a jackpot (value 64):
ts
bot.on("message", async (ctx) => {
const msg = await ctx.sendDice("🎰");
const result = msg.dice?.value ?? 0;
if (result === 64) {
await ctx.send("Jackpot! You hit the maximum!");
} else {
await ctx.send(`Slot result: ${result} — better luck next time!`);
}
});Build a simple basketball mini-game (🏀, values 1–5):
ts
bot.command("shoot", async (ctx) => {
const msg = await ctx.sendDice("🏀");
const score = msg.dice?.value ?? 0;
const verdict =
score >= 4 ? "Slam dunk!" : score >= 2 ? "Nice shot!" : "Missed!";
await ctx.send(verdict);
});Direct API call with bot.api.sendDice (useful outside message handlers):
ts
const msg = await bot.api.sendDice({
chat_id: 123456789,
emoji: "🎯",
});
const value = msg.dice?.value ?? 0;Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | The chat_id is invalid, the bot has never interacted with the user, or the chat does not exist. |
| 400 | Bad Request: wrong dice emoji | The emoji value is not one of the six supported emojis (🎲 🎯 🏀 ⚽ 🎳 🎰). |
| 403 | Forbidden: bot was blocked by the user | The user blocked the bot. Remove them from your active user list. |
| 429 | Too Many Requests: retry after N | Flood control triggered. Back off for the specified number of seconds. |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
- The value is truly random. Telegram generates the random value server-side — you cannot control or predict the outcome. Read
message.dice.valuefrom the returnedMessageobject. - Value ranges differ by emoji. 🎲 🎯 🎳 → 1–6 · 🏀 ⚽ → 1–5 · 🎰 → 1–64. Design game logic around the correct range for your chosen emoji.
- Omitting
emojidefaults to 🎲. If you want a specific animated emoji, always pass theemojiparameter explicitly. - The animation plays client-side. The rolled value is embedded in the message immediately, but the visual animation takes a few seconds to complete. Do not read the value before the
Messageis returned — the value is already final whensendDiceresolves. - Not suitable for real gambling. The dice is entertainment-only. Telegram reserves the right to change value ranges or behavior in future API versions.
protect_contentprevents forwarding. Use this in fair-play scenarios where users should not forward a lucky roll to another chat.
See Also
- Dice type — structure of the dice object in the returned message
- Message type — full structure of the returned message
- Keyboards overview — attaching inline keyboards for follow-up actions
- sendMessage — send a text response after reading the dice value
- auto-retry plugin — handle rate limits automatically