我想让一个机器人在不和谐上创建一个频道。我已经与不和谐令牌建立了联系:// Create a new Discord session using the provided bot token.dg, err := discordgo.New("Bot " + Token)if err != nil { fmt.Println("error creating Discord session,", err) return}// Register the channelCreate func as a callback for ChannelCreate events.dg.AddHandler(channelCreate)// Open a websocket connection to Discord and begin listening.err = dg.Open()if err != nil { fmt.Println("error opening connection,", err) return }}// channel is createfunc channelCreate(s *discordgo.Session, event *discordgo.ChannelCreate ) { // create channel here}如何在 https://gowalker.org/github.com/jonas747/discordgo#ChannelCreate 上使用 ChannelCreate 类型
1 回答
POPMUISE
TA贡献1765条经验 获得超5个赞
discordgo.MessageCreate是频道创建的事件。这意味着处理程序将在创建通道时触发。我不确定你希望机器人创建通道的条件是什么。假设你想要通过向机器人发送消息来创建通道。首先需要在消息事件上添加处理程序
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
// Ignore all messages created by the bot itself
if m.Author.ID == s.State.User.ID { return
} if m.Content == "create channel" {
s.GuildChannelCreate(guildID, name, type)
}
}类型为下列之一:
// Block contains known ChannelType valuesconst ( ChannelTypeGuildText ChannelType = iota ChannelTypeDM ChannelTypeGuildVoice ChannelTypeGroupDM ChannelTypeGuildCategory ChannelTypeGuildNews ChannelTypeGuildStore )
- 1 回答
- 0 关注
- 206 浏览
添加回答
举报
0/150
提交
取消
