setGameScore
Sets a user's game score.
Returns: On success, returns Message or True.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
user_id | Integer | Yes | User ID |
score | Integer | Yes | New score |
force | Boolean | Optional | Overwrite score even if lower |
disable_edit_message | Boolean | Optional | Don't edit message, send new one |
chat_id | Integer | Optional | Chat ID (for non-inline messages) |
message_id | Integer | Optional | Message ID (for non-inline messages) |
inline_message_id | String | Optional | Inline message ID |
Example request
curl
curl -s -X POST "https://api.telegram.org/bot$TOKEN/setGameScore" \
-H "Content-Type: application/json" \
-d '{"user_id":123456789,"score":100}'
Python
import requests
TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
f"https://api.telegram.org/bot{TOKEN}/setGameScore",
json={
"user_id": 123456789,
"score": 100
},
timeout=30,
)
print(resp.json())
JavaScript
const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/setGameScore`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"user_id": 123456789,
"score": 100
}),
});
console.log(await res.json());
Step-by-step guide: How to Create a Telegram Bot: Step by Step with BotFather and Python
Related methods
sendGameSends a game.getGameHighScoresReturns game high scores.