Skip to content

Bot.ID(): silent return of 0 on invalid or malformed token #277

Description

@Zoomish

Problem

Bot.ID() parses the numeric bot id from the token prefix (<id>:<secret>). On any parse error it returns 0 with no way for callers to distinguish:

  • invalid / placeholder token,
  • corrupted token string,
  • API misuse,

from a legitimate bot id that might theoretically collide with 0 (or simply: callers assume 0 means “error” but this is undocumented).

Current implementation:

func (b *Bot) ID() int64 {
	id, err := strconv.ParseInt(strings.Split(b.token, ":")[0], 10, 64)
	if err != nil {
		return 0
	}
	return id
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions