Use Lanyard API easily in your Go app!
- Initialize your project (
go mod init example.com/example
) - Add package (
go get github.com/barbarbar338/go-lanyard
)
Using without websocket:
package main
import (
"fmt"
"github.com/barbarbar338/go-lanyard"
)
func main() {
// User ID here π
res, err := lanyard.FetchUser("952574663916154960")
// Handle error
if err != nil {
// ...
panic(err)
}
// Handle presence data here
fmt.Println(res.Data.DiscordStatus)
}
Using with websocket:
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/barbarbar338/go-lanyard"
)
func main() {
// User ID here π
ws := lanyard.ListenUser("952574663916154960", func(data *lanyard.LanyardData) {
// Handle presence data here
fmt.Println(data.DiscordStatus)
})
sc := make(chan os.Signal, 1)
signal.Notify(
sc,
syscall.SIGINT,
syscall.SIGTERM,
os.Interrupt,
)
<-sc
fmt.Println("Closing client.")
// Destroy WS before exit
ws.Destroy()
}
Using websocket for watching multiple users:
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/barbarbar338/go-lanyard"
)
func main() {
// User IDs here π
ws := lanyard.ListenMultipleUsers([]string{"866849747603816468", "952574663916154960"}, func(data *lanyard.LanyardData) {
fmt.Println(data.DiscordStatus)
})
sc := make(chan os.Signal, 1)
signal.Notify(
sc,
syscall.SIGINT,
syscall.SIGTERM,
os.Interrupt,
)
<-sc
fmt.Println("Closing client.")
// Destroy WS before exit
ws.Destroy()
}
Copyright Β© 2021 BarΔ±Ε DEMΔ°RCΔ°.
Distributed under the GPL-3.0 License. See LICENSE
for more information.
Feel free to use GitHub's features.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/my-feature
) - Commit your Changes (
git commit -m 'my awesome feature my-feature'
) - Push to the Branch (
git push origin feature/my-feature
) - Open a Pull Request
Give a βοΈ if this project helped you!
- Mail: [email protected]
- Discord: https://discord.gg/BjEJFwh
- Instagram: https://www.instagram.com/ben_baris.d/
- Phineas - Creator of Lanyard API