voicy

package module
v0.0.0-...-6b9c757 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 12 Imported by: 1

README ΒΆ

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.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	DestroyedState = iota
	StoppedState
	ChangingState
	PausedState
	PlayingState
)

Variables ΒΆ

View Source
var (
	ErrDestroyed      = errors.New("this session has been destroyed and can no longer be used")
	ErrAlreadyPlaying = errors.New("something is already playing")
)

Functions ΒΆ

This section is empty.

Types ΒΆ

type Session ΒΆ

type Session struct {
	// contains filtered or unexported fields
}

func New ΒΆ

func New(context context.Context, state *state.State, ChannelID discord.ChannelID) (*Session, error)

func (*Session) Destroy ΒΆ

func (s *Session) Destroy()

func (*Session) Pause ΒΆ

func (s *Session) Pause()

func (*Session) PlayURL ΒΆ

func (s *Session) PlayURL(source string, isOpus bool) error

func (*Session) PlaybackPosition ΒΆ

func (s *Session) PlaybackPosition() time.Duration

func (*Session) Resume ΒΆ

func (s *Session) Resume()

func (*Session) Seek ΒΆ

func (s *Session) Seek(pos time.Duration)

func (*Session) State ΒΆ

func (s *Session) State() int

func (*Session) Stop ΒΆ

func (s *Session) Stop()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL