大佬教程收集整理的这篇文章主要介绍了Discord Bot 对一个事件多次响应,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
问题是当一首歌曲被添加到队列时,机器人会多次响应。当第一次运行命令时,它只响应一次,当第二次发生该事件时,它会响应两次。
示例: *玩加比博混搭 播放:Gabibbo Mashup-00:26。 第二次:*玩 Gabibbo Mashup 播放:Gabibbo Mashup - 00:26 播放:Gabibbo Mashup - 00:26)
Bulk
每次收到消息时,都会添加更多事件侦听器:
client.on("message",async (messagE) => {
// other stuff
distube.on("playSong",(message,queue,song) => message.chAnnel.send(
`Playing: **${song.namE}** - **${song.formattedDuration}**`
));
});
需要改为
client.on("message",async (messagE) => {
// other stuff
});
distube.on("playSong",song) => message.chAnnel.send(
`Playing: **${song.namE}** - **${song.formattedDuration}**`
));
const Discord = require('discord.js');
const client = new Discord.Client();
const keepAlive = require('./server.js');
const distube = new Distube(client,{ searchSongs: false,emitNewSongOnly: true })
const prefix = "*"
client.on("ready",() => {
console.log('I am ready')
});
client.on("message",async (messagE) => {
if (message.author.bot) return;
if (!message.content.startsWith(prefiX)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift();
// 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"}\``;
if (["p","play"].includes(command)){
if (!args[0]) return message.chAnnel.send('You must state something to play');
if (!message.member.voice.chAnnel) return message.chAnnel.send('You must be in a voice chAnnel to play music');
distube.play(message,args.join(" "));
}
if (command == 'stop') {
const bot = message.guild.members.cache.get(client.user.id);
if (!message.member.voice.chAnnel) return message.chAnnel.send('You must be in a voice chAnnel to stop music');
if (bot.voice.chAnnel !== message.member.voice.chAnnel) message.chAnnel.send('You must be in the same voice chAnnel as me.');
distube.stop(message,args.join(" "));
message.chAnnel.send('I have stopped that song for you')
}
if (["s","skip"].includes(command)){
distube.skip(messagE);
message.chAnnel.send('I have skipped that song')
}
if (command == 'queque') {
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 (["repeat","loop"].includes(command)) {
distube.setRepeatMode(message,parseInt(args[0]))
message.chAnnel.send(`${song.namE} is looped`)
}
if ([`3d`,`bassboost`,`echo`,`karaoke`,`nightcore`,`vaporwave`].includes(command)) {
let filter = distube.setFilter(message,command);
message.chAnnel.send("Current queue filter: " + (filter || "Off"));
}
});
// Distube event listeners,more in the documentation page
distube
.on("playSong",song) => message.chAnnel.send(
`Playing: **${song.namE}** - **${song.formattedDuration}**`))
.on("addSong",song) => message.chAnnel.send(
`Added **${song.namE}** - **${song.formattedDuration}** to the queue by ${song.user}`,))
.on("playList",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",playlist) => message.chAnnel.send(
`Added **${playlist.namE}** playlist (${playlist.songs.length} songs) to queue\n${status(queuE)}`
))
// DistubeOptions.searchSongs = true
.on("searchResult",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",E) => {
console.error(E)
message.chAnnel.send("An error encountered: " + E);
});
keepAlive();
client.login(process.env.TOKEN);
以上是大佬教程为你收集整理的Discord Bot 对一个事件多次响应全部内容,希望文章能够帮你解决Discord Bot 对一个事件多次响应所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。