@2pg/music 中文文档教程

发布于 3年前 浏览 30 项目主页 更新于 3年前

2PG Music

2PG 使用的简单音乐模块,使用 TypeScript 构建。

Discord

文档 - https://twopg.github.io/music

Example

npm i -S @2pg/music discord.js

< strong>ES6:

import { Client } from 'discord.js';
import { MusicClient } from '@2pg/music';

const music = new MusicClient();
const bot = new Client();

music.on('trackStart', (player, track) => player.textChannel?.send(`\`${track.title}\` - **${track.requestor}** started.`));

bot.on('message', async (msg) => {
  if (msg.author.bot) return;

  if (msg.content === '.play') {
    const player = getPlayer(msg);
    await player.play('discord bot dashboard intro', { member: msg.member });
  }
});

function getPlayer(msg) {
  return music.get(msg.guild.id)
    ?? music.create({
      voiceChannel: msg.member.voice.channel,
      textChannel: msg.channel
    });
}

bot.login('<your_bot_token>');

Discord

2PG Music

Simple music module, built with TypeScript, used by 2PG.

Discord

Docs - https://twopg.github.io/music

Example

npm i -S @2pg/music discord.js

ES6:

import { Client } from 'discord.js';
import { MusicClient } from '@2pg/music';

const music = new MusicClient();
const bot = new Client();

music.on('trackStart', (player, track) => player.textChannel?.send(`\`${track.title}\` - **${track.requestor}** started.`));

bot.on('message', async (msg) => {
  if (msg.author.bot) return;

  if (msg.content === '.play') {
    const player = getPlayer(msg);
    await player.play('discord bot dashboard intro', { member: msg.member });
  }
});

function getPlayer(msg) {
  return music.get(msg.guild.id)
    ?? music.create({
      voiceChannel: msg.member.voice.channel,
      textChannel: msg.channel
    });
}

bot.login('<your_bot_token>');

Discord

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文