You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Golang tgbotapi v5版本发送贴纸失败,求解决方案

解决go-telegram-bot-api v5版本发送贴纸失效问题

在v5版本中,库的API结构有调整,原v4的NewStickerShare快捷方法已不适用,需要通过tgbotapi.SendStickerConfig结构体来构建请求:

调整后的代码示例

// 构建贴纸发送配置
stickerConfig := tgbotapi.SendStickerConfig{
    BaseChat: tgbotapi.BaseChat{
        ChatID: update.Message.Chat.ID,
    },
    Sticker: "hereIsTheIDOfTheSticker", // 替换为你的贴纸ID
}

// 发送贴纸
_, err := bot.Send(stickerConfig)
if err != nil {
    // 错误处理
    log.Printf("发送贴纸失败: %v", err)
}

也可以使用v5保留的快捷构造函数简化代码:

stickerConfig := tgbotapi.NewSticker(update.Message.Chat.ID, "hereIsTheIDOfTheSticker")
_, err := bot.Send(stickerConfig)
if err != nil {
    log.Printf("发送贴纸失败: %v", err)
}

关键说明

  • v5版本重构了请求配置结构,所有发送类操作均需使用对应配置结构体,旧版本快捷方法已被移除或调整
  • 确保贴纸ID格式正确(如CAACAgQAAxkBAAEB...这类官方格式),无效ID会直接导致发送失败

内容的提问来源于stack exchange,提问作者Guskuskudu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 12:03:31