所以我想尝试做一些你可以用反应“输入”的东西,但由于某种原因它不起作用,而不是仅仅添加,它会替换最后一个然后继续下一个,然后替换那个一并重复。我如何使它正常工作?我正在尝试制作某种交互式不和谐计算器
client.on('message' , async msg => {
if(msg.content === "mb!calculate") {
msg.author.calculator = new Discord.MessageEmbed()
.setColor('0000ff')
.setTitle('Calculator')
.setDescription('>> ');
msg.author.calEmbed = await msg.channel.send(msg.author.calculator);
msg.author.calEmbed.react('1️⃣');
msg.author.calEmbed.react('2️⃣');
msg.author.calEmbed.react('3️⃣');
msg.author.calEmbed.react('4️⃣');
msg.author.calEmbed.react('5️⃣');
msg.author.calEmbed.react('6️⃣');
msg.author.calEmbed.react('7️⃣');
msg.author.calEmbed.react('8️⃣');
msg.author.calEmbed.react('9️⃣');
msg.author.actEmbed = msg.author.calEmbed.embeds[0];
}
})
client.on('messageReactionAdd', async (reaction, user) => {
if(reaction.partial) {
try {
await reaction.fetch();
} catch (error) {
console.error(error);
return;
}
}
if(reaction.message === user.calEmbed) {
reaction.users.remove(user.id);
if(reaction.emoji.name === '1️⃣') {
user.calculator.setDescription(user.actEmbed.description + '1');
} else if(reaction.emoji.name === '2️⃣') {
user.calculator.setDescription(user.actEmbed.description + '2');
} else if(reaction.emoji.name === '3️⃣') {
user.calculator.setDescription(user.actEmbed.description + '3');
} else if(reaction.emoji.name === '4️⃣') {
user.calculator.setDescription(user.actEmbed.description + '4');
} else if(reaction.emoji.name === '5️⃣') {
user.calculator.setDescription(user.actEmbed.description + '5');
} else if(reaction.emoji.name === '6️⃣') {
user.calculator.setDescription(user.actEmbed.description + '6');
} else if(reaction.emoji.name === '7️⃣') {
user.calculator.setDescription(user.actEmbed.description + '7');
} else if(reaction.emoji.name === '8️⃣') {
user.calculator.setDescription(user.actEmbed.description + '8');
} else if(reaction.emoji.name === '9️⃣') {
user.calculator.setDescription(user.actEmbed.description + '9');
}
user.calEmbed.edit(user.calculator);
user.actEmbed = user.calEmbed.embeds[0];
}
})
所以我正在做的是将变量添加到一个用户,以便多人可以同时使用它,而不是其他人的。我还没有完成,因为它正在做我上面说的。
答案 0 :(得分:0)
好的,我发现我做错了什么。我实际上不需要 user.actEmbed,因为正在对 user.calculator 进行更改,这意味着我所需要的只是将所有说“actEmbed”的内容更改为“计算器”。这是修改后的版本。
client.on('message' , async msg => {
if(msg.content === "mb!calculate") {
msg.author.calculator = new Discord.MessageEmbed()
.setColor('0000ff')
.setTitle('Calculator')
.setDescription('>> ');
msg.author.calEmbed = await msg.channel.send(msg.author.calculator);
msg.author.calEmbed.react('1️⃣');
msg.author.calEmbed.react('2️⃣');
msg.author.calEmbed.react('3️⃣');
msg.author.calEmbed.react('4️⃣');
msg.author.calEmbed.react('5️⃣');
msg.author.calEmbed.react('6️⃣');
msg.author.calEmbed.react('7️⃣');
msg.author.calEmbed.react('8️⃣');
msg.author.calEmbed.react('9️⃣');
}
})
client.on('messageReactionAdd', async (reaction, user) => {
if(reaction.partial) {
try {
await reaction.fetch();
} catch (error) {
console.error(error);
return;
}
}
if(reaction.message === user.calEmbed) {
reaction.users.remove(user.id);
if(reaction.emoji.name === '1️⃣') {
user.calculator.setDescription(user.calculator.description + '1');
} else if(reaction.emoji.name === '2️⃣') {
user.calculator.setDescription(user.calculator.description + '2');
} else if(reaction.emoji.name === '3️⃣') {
user.calculator.setDescription(user.calculator.description + '3');
} else if(reaction.emoji.name === '4️⃣') {
user.calculator.setDescription(user.calculator.description + '4');
} else if(reaction.emoji.name === '5️⃣') {
user.calculator.setDescription(user.calculator.description + '5');
} else if(reaction.emoji.name === '6️⃣') {
user.calculator.setDescription(user.calculator.description + '6');
} else if(reaction.emoji.name === '7️⃣') {
user.calculator.setDescription(user.calculator.description + '7');
} else if(reaction.emoji.name === '8️⃣') {
user.calculator.setDescription(user.calculator.description + '8');
} else if(reaction.emoji.name === '9️⃣') {
user.calculator.setDescription(user.calculator.description + '9');
}
user.calEmbed.edit(user.calculator)
}
})