go - 在 discordgo 中保持连接/ session 事件的更简洁方法?

标签 go

我正在使用 github.com/bwmarrin/discordgo包裹 我在示例中看到保持连接或“ session ”事件的方法是使用以下内容:

<-make(chan struct{})

但它看起来有点乱,这是保持它存活的最好方法还是有其他方法。

最佳答案

您没有提供指向示例的链接,所以我们只能猜测。例如,我的猜测,

the last bit of code in our main function:

<-make(chan struct{})

We're creating a channel that takes an empty struct that waits for input. This is a SUPER hacky way of making our main function sit and wait forever while not using any CPU.

https://boostlog.io/@cuken/writing-a-simple-discord-bot-in-go-part-1-5ae6a1d647018500491f42bb


你试过吗?

The Go Programming Language Specification

Select statements

select {}  // block forever

关于go - 在 discordgo 中保持连接/ session 事件的更简洁方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57240085/

相关文章:

go - gobot 中转换的参数太多

postgresql - 使用数组去 postgres `SELECT * IN`

macos - Intellij IDEA (Golang) 使用/private/var/folders/

go - 将参数作为接口(interface)传递

java - 通过编程语言访问 Skype

apache - Golang 无法识别 Close-Notifier

go - 在 go 编译器中使用 run 命令时,可执行文件会发生什么情况?

docker - 使用 Go docker SDK 的二进制 TLS 配置失败

xml - Go语言中从xml中解码数组

http - 如何使用RoundTrip跟踪请求大小?