Giter VIP home page Giter VIP logo

spotify's Introduction

npm peer dependency version npm GitHub Repo stars Discord

Buy Me a Coffee at ko-fi.com

@distube/spotify

A DisTube custom plugin for supporting Spotify URL.

Feature

This plugin grabs the songs on Spotify then searches on YouTube and plays with DisTube.

Installation

npm install @distube/spotify@latest

Usage

const Discord = require("discord.js");
const client = new Discord.Client();

const { DisTube } = require("distube");
const { SpotifyPlugin } = require("@distube/spotify");
const distube = new DisTube(client, {
  plugins: [new SpotifyPlugin()],
});

Documentation

SpotifyPlugin([SpotifyPluginOptions])

  • SpotifyPluginOptions.parallel: Default is true. Whether or not searching the playlist in parallel.
  • SpotifyPluginOptions.emitEventsAfterFetching: Default is false. Emits addList and playSong event before or after fetching all the songs.

    If false, DisTube plays the first song -> emits addList and playSong events -> fetches all the rest
    If true, DisTube plays the first song -> fetches all the rest -> emits addList and playSong events

  • SpotifyPluginOptions.api: (Optional) Spotify API options.
    • SpotifyPluginOptions.api.clientId: Client ID of your Spotify application (Optional - Used when the plugin cannot get the credentials automatically)
    • SpotifyPluginOptions.api.clientSecret: Client Secret of your Spotify application (Optional - Used when the plugin cannot get the credentials automatically)
    • SpotifyPluginOptions.api.topTracksCountry: Country code of the top artist tracks (ISO 3166-1 alpha-2 country code). Default is US.

Example

new SpotifyPlugin({
  parallel: true,
  emitEventsAfterFetching: false,
  api: {
    clientId: "SpotifyAppClientID",
    clientSecret: "SpotifyAppClientSecret",
    topTracksCountry: "VN",
  },
});
Use SoundCloudPlugin to search instead of YouTube
import { DisTube } from "distube";
import { SpotifyPlugin } from "@distube/spotify";
import { SoundCloudPlugin } from "@distube/soundcloud";

const scPlugin = new SoundCloudPlugin();

class NewSpotifyPlugin extends SpotifyPlugin {
  override async search(query: string) {
    try {
      return new Song((await scPlugin.search(query, { limit: 1 }))[0]);
    } catch {
      return null;
    }
  }
}

const distube = new DisTube(client, {
  plugins: [new NewSpotifyPlugin(), scPlugin],
});

spotify's People

Contributors

decahedron1 avatar skick1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spotify's Issues

Class extends value undefined

I've added this code to play music from Spotify.

const DisTube = require('distube')
const client = new Discord.Client()
const distube = new DisTube(client, {
    searchSongs: 10,
    emitNewSongOnly: true,
    plugins: [new SpotifyPlugin({ parallel: true })]
})

But it gives this error.

/home/runner/Groover-Beta/node_modules/@distube/spotify/index.js:6
module.exports = class SpotifyPlugin extends CustomPlugin {
                                             ^

TypeError: Class extends value undefined is not a constructor or null

DeprecationWarning error

Hi,
I am facing this problem, anyone have an idea to solve it?

(node:13632) DeprecationWarning: Passing Message for DisTube#play is deprecated, use BaseGuildVoiceChannel instead.

Capture
capture1

Node : v19
Discord : v12
Distube : v3

if (track.type !== "track") Cannot read properties of null (reading 'type')

When i add a playlist to the queue i will get this error

/home/tijmen/musicadev/node_modules/@distube/spotify/dist/index.js:280
if (track.type !== "track")
^

TypeError [PlayError]: https://open.spotify.com/playlist/6nOdNZWcNjURpp2lcMvjDU?si=f9920966151f4e47
Cannot read properties of null (reading 'type')
at /home/tijmen/musicadev/node_modules/@distube/spotify/dist/index.js:280:19
at Array.map ()
at SpotifyPlugin.play (/home/tijmen/musicadev/node_modules/@distube/spotify/dist/index.js:279:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async DisTube.play (/home/tijmen/musicadev/node_modules/distube/dist/index.js:2264:13)

Node.js v18.12.1

Further information:

  • Plugin version: 1.5.0
  • DisTube version: 4.0.4
  • discord.js version: 14.7.1
  • Node.js version: 18.12.1
  • Operating system: Ubuntu 22.04.1 LTS

Error when playlist contains local files

Please describe your problem in as much detail as possible:

Resolving fails when the playlist contains a local file

TypeError: Cannot read properties of undefined (reading 'url')
    at SpotifyPlugin.play (../node_modules/@distube/spotify/index.ts:121:40)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Further information:

  • Plugin version: 0.6.3
  • DisTube version: 3.0.0-beta.38
  • discord.js version: 13.1.0
  • Node.js version: 16.9.1
  • Operating system: Arch Linux

Unexpected Token

My console always gives me this error:

if (Array.isArray(queue.songs) && queue.songs[0]?.streamURL) resolve(clearInterval(check));
^

SyntaxError: Unexpected token '.'

this error is in the index.js of this plugin

Large playlists cause a freeze

Please describe your problem in as much detail as possible:
When I try to play a large spotify playlist (600 songs), it causes my bot to freeze due to a large CPU increase.
I think it would be nice to be able to set a limit of songs you take so the bot doesn't have to load everything.

Further information:

  • Plugin version: 1.0.0
  • DisTube version: 3.0.3
  • discord.js version: 13.3.1
  • Node.js version: 16.11.1
  • Operating system: Microsoft Windows 11

Distube spotify plugin problem.

I copied the documentation on npmjs.com and i get an error:

TypeError: Class extends value undefined is not a constructor or null
at Object. (C:\Users\Brendon\Desktop\kream-testing\node_modules@distube\spotify\index.js:6:46)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (C:\Users\Brendon\Desktop\kream-testing\index.js:64:23)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47

Class extends value undefined is not a constructor or null "distube_1.CustomPlugin"

Further information:

  • Plugin version: 0.6.4
  • DisTube version: 2.8.18
  • discord.js version: 12.5.3
  • Node.js version: 16.9.1
  • Operating system: Windows 10 Family

Error:

D:\BOT ACTIVER DISCORD\Mes bots privé\RadioJap\node_modules@distube\spotify\dist\index.js:45
class SpotifyPlugin extends distube_1.CustomPlugin {
^

TypeError: Class extends value undefined is not a constructor or null
at Object. (D:\BOT ACTIVER DISCORD\Mes bots privé\RadioJap\node_modules@distube\spotify\dist\index.js:45:39)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at Object. (D:\BOT ACTIVER DISCORD\Mes bots privé\RadioJap\radiojap-dev.js:47:27)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

==================

==================

My code:

const DisTube = require('distube')
const { SpotifyPlugin } = require("@distube/spotify");
const distube = new DisTube(client,
{
ytdlOptions: {
quality: 'highestaudio',
filter: 'audioonly',
},
leaveOnFinish: false,
leaveOnStop: false,
leaveOnEmpty: false,
updateYouTubeDL: true,
searchSongs: true,
emitNewSongOnly: true,
plugins: [
new SpotifyPlugin({
parallel: true,
emitEventsAfterFetching: false,
api: {
clientId: "2f66e4ab0bb94779b6fd3e76fd05ffdb",
clientSecret: "001792c206b14efbbede838640e891d1",
},
})
],
})

Someone can help me ??

The package doesen't work!

I got this error:
postinstall:container: timing audit body Completed in 1m /home/container/node_modules/@distube/spotify/dist/index.js:44
class SpotifyPlugin extends distube_1.CustomPlugin {
TypeError: Class exten

Further information:

  • Plugin version:1.1.0
  • DisTube version:2.8.15
  • discord.js version:12.5.3
  • Node.js version:12
  • Operating system:windows

No result found when using <DisTube>.search() method on a Spotify link!

Please describe your problem in as much detail as possible:

The Distube options:

{
            updateYouTubeDL: false,
            youtubeCookie: this.settings.main.cookie,
            searchSongs: 10,
            emitNewSongOnly: true,
            leaveOnStop: false,
            plugins: [new SpotifyPlugin(), new SoundCloudPlugin()],
}

Error Message:

DisTubeError [NO_RESULT]: No result found
    at DisTube.search (C:\Users\Major\Documents\github\Rayila\node_modules\distube\src\DisTube.ts:329:39)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
[ERROR] 11:46:45 DisTubeError [NO_RESULT]: No result found

⚠️ NOTE: After some testing I think the issue with <DisTube>.search(); because <DisTube>.playVoiceChannel(); is working fine...

Further information:

  • Plugin version: 1.0.0
  • DisTube version: 3.0.3
  • discord.js version: 13.3.1
  • Node.js version: 16.6.1
  • Operating system: Windows 11 21h1 Build 22000

Spotify error

when i want to play a playlist i wil get this error

Musica > TypeError [PlayError]: *******
xx Musica > Cannot read properties of undefined (reading '0')
xx Musica > at SpotifyPlugin.play (/home/tijmen/musica/node_modules/@distube/spotify/dist/index.js:183:36)
xx Musica > at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
xx Musica > at async DisTube.play (/home/tijmen/musica/node_modules/distube/dist/index.js:2264:13)

Error Recieved on Start

/home/runner/Moderatrix/node_modules/@distube/spotify/index.js:72
            if (Array.isArray(queue.songs) && queue.songs[0]?.streamURL) resolve(clearInterval(check));
                                                             ^

SyntaxError: Unexpected token '.'

I recieve this error when I tried to start my bot

Large playlists cause a freeze

Please describe your problem in as much detail as possible:
When I play a large spotify playlist, my bot's voice freezes.
I don't understand why there is this problem since my bot does not exceed its CPU limit (it has 4 cores).
I wish I didn't have this problem without having to set the parallel option to false because otherwise it is too slow to search.
unknown

Further information:
Plugin version: 1.2.1
DisTube version: 3.3.2
discord.js version: 13.6.0
Node.js version: 16.13.2
Operating system: Microsoft Windows 11

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.