Skip to content

πŸ“’ A Simple way to play music on Discord using Golang

License

Notifications You must be signed in to change notification settings

ItsClairton/voicy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Voicy

A simple way to play music on Discord using Golang

πŸ“š Requirements

  • Voicy only supports arikawa for now.
  • You need to have ffmpeg installed on your system.

πŸ“‹ Example

package main

import (
	"context"

	"github.com/ItsClairton/voicy"
	"github.com/diamondburned/arikawa/v3/discord"
	"github.com/diamondburned/arikawa/v3/gateway"
	"github.com/diamondburned/arikawa/v3/state"
	"github.com/kkdai/youtube/v2"
)

var (
	token   = "Your bot token here"
	channel = discord.ChannelID(806346482134417433) // Voice channel ID here
	client  = youtube.Client{}
)

func main() {
	session := state.NewWithIntents("Bot "+token, gateway.IntentGuilds, gateway.IntentGuildVoiceStates)
	if err := session.Open(context.Background()); err != nil {
		panic(err)
	}

	defer session.Close()

	voice, err := voicy.New(context.Background(), session, channel)
	if err != nil {
		panic(err)
	}

	video, err := client.GetVideo("https://www.youtube.com/watch?v=LNuVDtUUmd4")
	if err != nil {
		panic(err)
	}

	stream, err := client.GetStreamURL(video, &video.Formats.WithAudioChannels()[0])
	if err != nil {
		panic(err)
	}

	if err := voice.PlayURL(stream, false); err != nil {
		panic(err)
	}
}

❓ Questions or bugs?

Don't hesitate to create an issue or a PR.

About

πŸ“’ A Simple way to play music on Discord using Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages