Search code examples
telegramtelegram-botpython-telegram-bot

How can I make a telegram bot send the dice sticker?


I'm doing a bot that sends messages with the respective command, the easy text message I'm able to send but not an animated sticker.

I've been trying to use the message.reply_sticker and the reply_dice to send the dice emoji and know which outcome will be but I can't seem to be able to send anything, what should I put as a parameter? I tried to find the file_id but it just comes out as "dice".


Solution

  • If you want your bot to send a dice, you'll need to use the sendDice method.

    No parameters (except chat_id are required), but you can set emoji to use a custom emoji (see documentation)


    https://api.telegram.org/bot<MY-BOT-TOKEN>/sendDice?chat_id=132456
    

    Regarding the 'outcome', Telegram Bot API will return a Message object, which in this case holds the Dice object which will tell you the outcome:

    {
        "ok": true,
        "result": {
            "message_id": 835,
            "from": {
                // ...
            },
            "chat": {
                // ...
            },
            "date": 1693323452,
            "dice": {
                "emoji": "🎲",
                "value": 1
            }
        }
    }
    

    Since you've tagged the library; the sendDice is available on the Bot class.

    For more information and examples, see the relevant documentation.