Giter Site home page Giter Site logo

music.kyp's Introduction

music.kyp โœจ

easy discord music bot building โœจ๐ŸŽถ

Installation ๐Ÿ› 

npm i music.kyp

why music.kyp ๐Ÿค”

  • easy to use
  • just make the ytdl and souncloud and spotify functions easer
  • simple and powerful

useg ๐Ÿ‘จโ€๐Ÿ’ป

first make your default discord.js source

const { Client, Intents } = require("discord.js");
const client = new Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MEMBERS,
        Intents.FLAGS.GUILD_BANS,
        Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
        Intents.FLAGS.GUILD_INTEGRATIONS,
        Intents.FLAGS.GUILD_WEBHOOKS,
        Intents.FLAGS.GUILD_INVITES,
        Intents.FLAGS.GUILD_VOICE_STATES,
        Intents.FLAGS.GUILD_PRESENCES,
        Intents.FLAGS.GUILD_MESSAGES,
        Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
        Intents.FLAGS.GUILD_MESSAGE_TYPING,
        Intents.FLAGS.DIRECT_MESSAGES,
        Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
        Intents.FLAGS.DIRECT_MESSAGE_TYPING
    ]
});
client.login("<your discord bot token>");

now import the music.kyp module

const { Client: music } = require("music.kyp");

make a new music client

const player = new music({ client }); // the "client" is a normal discord.js@13 client
const player = new music({ token: "your discord bot token" }); // you can also do this

now the "player" have alot of functions to export:

const player = new music({ client });

player.musicClient
// if you insert a token to "player constructor" this will return the "Discord.Client"
player.play("Discord.Message | Discord.CommandInteraction", "songName <string>");
// play a music
player.loop("Discord.Message | Discord.CommandInteraction", "arg <boolean>");
// make the song on loop
player.pause("Discord.Message | Discord.CommandInteraction");
// pause the music
player.resume("Discord.Message | Discord.CommandInteraction");
// resume the music
player.search("Discord.Message | Discord.CommandInteraction", "arg <string>");
// search for a music on youtube
player.skip("Discord.Message | Discord.CommandInteraction");
// skip the song
player.stop("Discord.Message | Discord.CommandInteraction");
// stop the music
player.volume("Discord.Message | Discord.CommandInteraction", "percentage <number>");
// change the music volume percentage
player.connect("Discord.Message | Discord.CommandInteraction");
// join a voice channel
player.disconnect("Discord.Message | Discord.CommandInteraction");
// leave the voice channel

now the player have one more thing!, the events (its return a values of all the "player" functions)

// simple example

const player = new music({ client });

player.events
    .on("disconnected", (msg, connection, voiceChannel) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `bot disconnected to <#${voiceChannel.id}>` }) : "bad reading";
    })
    .on("connected", (msg, connection, voiceChannel) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `bot connected to <#${voiceChannel.id}>` }) : "bad reading";
    })
    .on("playSong", (msg, song) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `**${song.title}** is playing!` }) : "bad reading";
    })
    .on("addSong", (msg, song) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `**${song.title}** got added!` }) : "bad reading";
    })
    .on("stopSong", (msg) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `Music got stoped!.` }) : "bad reading";
    })
    .on("resumeSong", (msg) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `Music got resumed!.` }) : "bad reading";
    })
    .on("pauseSong", (msg) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `Music got paused!.` }) : "bad reading";
    })
    .on("volumeSong", (msg, percentage) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `Music volume has changed to: ${percentage}%` }) : "bad reading";
    })
    .on("skipSong", (msg) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `Music got skiped!.` }) : "bad reading";
    })
    .on("loopSong", (msg, arg) => {
        let channel = msg.channel.type;
        if (channel.type == "dm") return;
        channel.send ? channel.send({ content: `Music got looped ${arg}!.` }) : "bad reading";
    })
    .on("search", (msg, arg, result) => {
        let channel = msg.channel;
        if (channel.type == "dm") return;
        channel.send(result.map((video, index) => `#${index} - ${video.url}`).join("\n"))
    });

// thare are one more event and its custom for discord.js v13 "speech"
client.on("speech", (msg) => {
    if (msg.content) {
        msg.author.send(msg.content);
    }
});
// simple example to how you can use it with the package
client.on("speech", (msg) => {
    if (msg.content) {
        msg.author.send(msg.content)
        if (msg.content.includes("play") || msg.content.includes("ุดุบู„")) player.play(msg, msg.content.split(' ').slice(' ').join(' '));
        else if (msg.content.includes("stop") || msg.content.includes("ูˆู‚ู")) player.stop(msg);
        else if (msg.content.includes("pause") || msg.content.includes("ุงุณูƒุช")) player.pause(msg);
        else if (msg.content.includes("resume") || msg.content.includes("ูƒู…ู„")) player.resume(msg);
        else if (msg.content.includes("skip") || msg.content.includes("ุงู„ูŠ ุจุนุฏู‡")) player.skip(msg);
    }
});

you have one more thing you can export from the package, the server queue server queue is actually a javascript map;

you can export it by:

const { Client: music, Queue } = require("music.kyp");
// "Queue" is a javascript map so you can set and get values from it, example:

Queue.get("<guildID>"); // this return the guild queue it have to be something like that:

/*
{
    vc: <Discord.VoiceChannel>,
    tc: <Discord.TextChannel>,
    connection: <@discordjs/voice connection>,
    songs: [
        {
            url: "<the song url>",
            details: "<the song detals>"
        },
        ...
    ],
    loop: <boolean>
}
*/

finally this a full example and the docs if you need:

normal music bot example

speech music bot example

Docs

and that's it :)

the source on github if you won't to pull any update :)))

bay ๐Ÿ‘‹

music.kyp's People

Contributors

n1r0tka avatar

Stargazers

 avatar

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.