# README
DiscordGo Audio
This package is a wrapper on top of DiscordGo thast provides an easier to use interface for playing, listening, and controlling audio in a Discord voice channel. This package provides an AudioPlayer interface and handles AudioPlayer state accross servers. It also provides helpful functions for interacting with Discord voice channels. This package only supports one playing instance per server.
Getting Started
Prerequisites
- You must have ffmpeg in your path and Opus libs already installed
Installation
This assumes you already have a working Go environment, if not please see this page first.
go get github.com/bafifi/discordgoaudio
Import the package into your project
go import "github.com/bafifi/discordgoaudio"
Example Usage
AudioPlayer
Functionality to control audio playback
func skip(s *discordgo.Session, guildId string) {
state := discordgoaudio.GetServerAudioState(m.GuildID)
if state.Player.StopAudioChannel != nil {
state.Player.StopAudioChannel <- true
}
}
func pause(s *discordgo.Session, guildId string) {
state := discordgoaudio.GetServerAudioState(m.GuildID)
if state.Player.PauseAudioChannel != nil {
state.Player.PauseAudioChannel <- true
}
}
func resume(s *discordgo.Session, guildId string) {
state := discordgoaudio.GetServerAudioState(m.GuildID)
if state.Player.ResumeAudioChannel != nil {
state.Player.ResumeAudioChannel <- true
}
}
Record Voice Channel Audio
Starts Recording Discord Audio
func saveAudio(s *discordgo.Session, guildID, channelID string) {
saveLocation := "some/path/here/" // path the audio is saved to. each user will have their own file in this dir
silenceThreshold := 2 * time.Minute // time the user is silent before thier audio is saved
discordgoaudio.SaveChannelAudio(s, guildID, silenceThreshold, saveLocation)
}
Automatic Disconnect
Disconnect from voice timer (Run Once at Start)
discordgoaudio.CheckDisconnectTimer(session, discordgoaudio.GetServerAudioState(guildID), guildID, 5 * time.Minute)
Other Discord Voice Helper Function
- FindUserVoiceChannel
- JoinChannel
- GetUsersInVoiceChannels
- IsChannelEmpty
# Functions
CheckDisconnectTimer starts a goroutine that checks if the bot should disconnect from the voice channel.
FindUserVoiceChannel finds the voice channel ID for a given user in any guild.
GetServerAudioState returns the AudioState for a given guild ID.
GetUsersInVoiceChannels returns a list of user IDs and their corresponding voice channel IDs for a given guild.
IsChannelEmpty checks if a voice channel is empty.
JoinChannel joins a voice channel and plays audio from the specified path.
LeaveVoice disconnects from the voice channel in the specified guild.
No description provided by the author
SaveChannelAudio joins a voice channel and saves audio from it.
# Structs
No description provided by the author