Coder Social home page Coder Social logo

basic-bot's People

Contributors

leonx74 avatar

Watchers

 avatar

basic-bot's Issues

Index.js

const Discord = require('discord.js'),
DisTube = require('distube'),
client = new Discord.Client(),
config = {
prefix: ".",
token: process.env.TOKEN || "Your Discord Token"
};

// Create a new DisTube
const distube = new DisTube(client, { searchSongs: true, emitNewSongOnly: true });

client.on('ready', () => {
console.log(Logged in as ${client.user.tag}!);
});

client.on("message", async (message) => {
if (message.author.bot) return;
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();

if (command == "play")
    distube.play(message, args.join(" "));

if (["repeat", "loop"].includes(command))
    distube.setRepeatMode(message, parseInt(args[0]));

if (command == "stop") {
    distube.stop(message);
    message.channel.send("Stopped the music!");
}

if (command == "skip")
    distube.skip(message);

if (command == "queue") {
    let queue = distube.getQueue(message);
    message.channel.send('Current queue:\n' + queue.songs.map((song, id) =>
        `**${id + 1}**. ${song.name} - \`${song.formattedDuration}\``
    ).slice(0, 10).join("\n"));
}

if ([`3d`, `bassboost`, `echo`, `karaoke`, `nightcore`, `vaporwave`].includes(command)) {
    let filter = distube.setFilter(message, command);
    message.channel.send("Current queue filter: " + (filter || "Off"));
}

});

// Queue status template
const status = (queue) => Volume: \${queue.volume}%` | Filter: `${queue.filter || "Off"}` | Loop: `${queue.repeatMode ? queue.repeatMode == 2 ? "All Queue" : "This Song" : "Off"}` | Autoplay: `${queue.autoplay ? "On" : "Off"}``;

// DisTube event listeners, more in the documentation page
distube
.on("playSong", (message, queue, song) => message.channel.send(
Playing \${song.name}` - `${song.formattedDuration}`\nRequested by: ${song.user}\n${status(queue)})) .on("addSong", (message, queue, song) => message.channel.send(Added ${song.name} - `${song.formattedDuration}` to the queue by ${song.user})) .on("playList", (message, queue, playlist, song) => message.channel.send(Play `${playlist.name}` playlist (${playlist.songs.length} songs).\nRequested by: ${song.user}\nNow playing `${song.name}` - `${song.formattedDuration}`\n${status(queue)})) .on("addList", (message, queue, playlist) => message.channel.send(Added `${playlist.name}` playlist (${playlist.songs.length} songs) to queue\n${status(queue)} )) // DisTubeOptions.searchSongs = true .on("searchResult", (message, result) => { let i = 0; message.channel.send(Choose an option from below\n${result.map(song => **${++i}**. ${song.name} - \${song.formattedDuration}`).join("\n")}\n*Enter anything else or wait 60 seconds to cancel*);
})
// DisTubeOptions.searchSongs = true
.on("searchCancel", (message) => message.channel.send(Searching canceled))
.on("error", (message, e) => {
console.error(e)
message.channel.send("An error encountered: " + e);
});

client.login(config.token);

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.