github.com/meowstercatel/discordgo@v0.0.0-20250615204139-29b43d676735/discord.go (about) 1 // Discordgo - Discord bindings for Go 2 // Available at https://github.com/bwmarrin/discordgo 3 4 // Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 // This file contains high level helper functions and easy entry points for the 9 // entire discordgo package. These functions are being developed and are very 10 // experimental at this point. They will most likely change so please use the 11 // low level functions if that's a problem. 12 13 // Package discordgo provides Discord binding for Go 14 package discordgo 15 16 import ( 17 "net/http" 18 "runtime" 19 "time" 20 21 "github.com/gorilla/websocket" 22 ) 23 24 // VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/) 25 const VERSION = "0.29.0" 26 27 // New creates a new Discord session with provided token. 28 // If the token is for a bot, it must be prefixed with "Bot " 29 // e.g. "Bot ..." 30 // Or if it is an OAuth2 token, it must be prefixed with "Bearer " 31 // e.g. "Bearer ..." 32 func New(token string) (s *Session, err error) { 33 34 // Create an empty Session interface. 35 s = &Session{ 36 State: NewState(), 37 Ratelimiter: NewRatelimiter(), 38 StateEnabled: true, 39 Compress: true, 40 ShouldReconnectOnError: true, 41 ShouldReconnectVoiceOnSessionError: true, 42 ShouldRetryOnRateLimit: true, 43 ShardID: 0, 44 ShardCount: 1, 45 MaxRestRetries: 3, 46 Client: &http.Client{Timeout: (20 * time.Second)}, 47 Dialer: websocket.DefaultDialer, 48 UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")", 49 sequence: new(int64), 50 LastHeartbeatAck: time.Now().UTC(), 51 } 52 53 // Initialize the Identify Package with defaults 54 // These can be modified prior to calling Open() 55 s.Identify.Compress = true 56 s.Identify.LargeThreshold = 250 57 s.Identify.Properties.OS = runtime.GOOS 58 s.Identify.Properties.Browser = "DiscordGo v" + VERSION 59 s.Identify.Intents = IntentsAllWithoutPrivileged 60 s.Identify.Token = token 61 s.Token = token 62 63 return 64 }