Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // EarrapePotter.js 2018/06/24 @author sanyo[jp]
- // This program works with node.js
- // **Please add the library below**
- // npm install discord.js
- // npm install node-opus
- // **Run**
- // node EarrapePotter.js
- // Bot user token
- const TOKEN = "Token";
- // 音割れポッター sound file path
- const EARRAPE_POTTER = "音割れポッター.mp4"
- // play volume
- const VOLUME = 1
- const Discord = require("discord.js");
- const client = new Discord.Client();
- client.on('message', msg => {
- var command = msg.content.trim().toLowerCase();
- // play
- if (/^\?{6,}$/.test(command)) {
- var guild = client.guilds.get(msg.guild.id);
- var voiceChannel = getVoiceChannel(guild, msg.author);
- if (voiceChannel != null) {
- if (voiceChannel.connection == null) {
- // play
- voiceChannel.join().then(voiceConnection => {
- playEarrapePotter(voiceConnection);
- }).catch(console.log);
- } else {
- // replay
- var voiceConnection = voiceChannel.connection;
- var dispatcher = voiceConnection.dispatcher;
- dispatcher.removeAllListeners('end');
- dispatcher.end();
- playEarrapePotter(voiceConnection);
- }
- }
- }
- // stop
- if (/^!\?*$/.test(command)) {
- var guild = client.guilds.get(msg.guild.id);
- var voiceChannel = getVoiceChannel(guild, msg.author);
- if (voiceChannel != null && voiceChannel.connection != null && voiceChannel.connection.dispatcher != null) {
- voiceChannel.connection.dispatcher.end();
- }
- }
- });
- function playEarrapePotter(voiceConnection) {
- var dispatcher = voiceConnection.playFile(EARRAPE_POTTER);
- dispatcher.on('end', () => {
- voiceConnection.channel.leave();
- log("leave");
- });
- dispatcher.setVolume(VOLUME);
- log("play");
- }
- function getVoiceChannel(guild, user) {
- for (var voiceChannel of guild.channels.values()) {
- if (voiceChannel.type !== 'voice')
- continue;
- for (var member of voiceChannel.members.values())
- if (member.user.id === user.id)
- return voiceChannel;
- }
- }
- function log(str) {
- console.log(new Date().toString() + ": " + str);
- }
- client.login(TOKEN);
- client.on('ready', () => {
- log('ready!');
- });
Add Comment
Please, Sign In to add comment