discordjs 有一些我不明白的地方.我想制作一个机器人,在人们对消息做出反应时列出他们.它部分有效,当输入命令的人(或之前输入过命令的人)对机器人的消息做出反应时,消息会立即编辑.但是当它是从未输入过命令的人时,它并没有更新.
There's something I don't understand with discordjs. I want to make a bot which lists people when they react on a message. It partially works, when the guy who enter the commands (or who has enter a command before) reacts to the bot's message, the message edits immediately. But when it's someone who has never entered command, it didn't update.
const Discord = require('discord.js');
const client = new Discord.Client();
var auth = require('./auth.json');
const regexTime = new RegExp('^(0[0-9]|1[0-9]|2[0-3]|[0-9])([:|h])([0-5][0-9])?$');
var messageBot = "";
var time;
var timer;
var commandeValide=false;
var date = new Date;
var heureMs;
client.on('ready', () => {
console.log(client.guilds.fetch())
});
client.on('message', msg => {
if (msg.content.substring(0,1) === '!') {
var args = msg.content.substring(1).split(' ');
var cmd = args[0];
switch(cmd){
case 'amongus':
dateGame = args[1];
time = args[2];
messageBot = '@everyone Est-ce que des personne veulent faire un Among us à '+ time + ' le '+ dateGame;
if ( dateGame != undefined && time != undefined ){
var heure = time.split('h')[0] * 3600000;
var minute = time.split('h')[1] * 60000;
var temps = heure + minute;
heureMs = date.getHours() * 3600000 + date.getMinutes() * 60000;
if(regexTime.test(time) && isDate(dateGame)){
if(temps>heureMs){
commandeValide=true;
msg.channel.send(messageBot).then(sendMessage => {
sendMessage.react('✅')
});
timer = temps - heureMs;
}
}else{
msg.reply("Veuillez rentrer une heure ou une date valide!");
commandeValide=false;
}
}else{
msg.reply("Veuillez rentrer une heure et/ou une date s'il vous plaît! (exemple: !amongus 19/04 20h)");
commandeValide=false;
}
}
}
if(commandeValide){
const filter = (reaction, user) => {
console.log(client.users.cache);
//return ['✅'].includes(reaction.emoji.name);
return reaction.emoji.name === '✅' && user.id !== msg.author.id;
};
const collector = msg.createReactionCollector(filter, { dispose: true, time: timer }); //dispose: true permet d'utiliser remove
collector.on('collect', (reaction, user) => {
reaction.users.fetch().then((user) => {
updateMessage(user.array(),msg);
});
});
collector.on('remove', (reaction, user) => {
reaction.users.fetch().then((user) => {
updateMessage(user.array(),msg);
});
});
collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
}
});
function updateMessage(tab, msg){
var listparticipant = "";
tab.forEach(user => {
if(user.id !== auth.server_id){
listparticipant += "- " + user.username + "
";
}
})
msg.edit(messageBot + "
" + listparticipant);
console.log(listparticipant);
}
client.login(auth.token);
Discord 改变了它们发出事件的数量,请确保将正确的意图放在您的机器人上,然后重试!
Discord changed how much they emit events, make sure to put he proper intents on your bot and try again!
const client = new Discord.Client({
ws : {
intents: [
'GUILD_MEMBERS',
'GUILD_MESSAGES',
'GUILD_MESSAGE_REACTIONS' //<--- the intent you need to detect reactions on messages in a guild
]
}
});
这篇关于未检测到 Discord js 反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 discord.js 检测图像并响应Using discord.js to detect image and respond(使用 discord.js 检测图像并响应)
检查 Discord 服务器中是否存在用户 IDCheck if user ID exists in Discord server(检查 Discord 服务器中是否存在用户 ID)
公会成员添加不起作用(discordjs)Guild Member Add does not work (discordjs)(公会成员添加不起作用(discordjs))
使用 REPLIT 创建我的第一个机器人,但总是错误Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 创建我的第一个机器人,但总是错误 Discord.JS)
如何为我的 Discord.js 机器人编写事件/命令处理程How do I code event/command handlers for my Discord.js bot?(如何为我的 Discord.js 机器人编写事件/命令处理程序?)
如何从 Discord.js 中的用户名中查找用户 ID?How to find a User ID from a Username in Discord.js?(如何从 Discord.js 中的用户名中查找用户 ID?)