【发布时间】:2021-04-15 08:14:51
【问题描述】:
我正在尝试通过存储消息 ID 来检查特定消息的反应。我正在使用 discord.js。
问题
问题是,在使用我的代码时,我收到此错误:TypeError: Cannot read property 'id' of undefined。也许是因为它是一个嵌入?我想要做的是获取已发送嵌入的 id 并将其写入文件。然后,在处理反应的代码中,我应该得到写在文件上的 id,并测试这是否是添加反应的正确消息。
我的代码
async function tembed(message) {
const mention = message.mentions.members.first();
if (mention.roles.cache.find(r => r.name === "dittatore")) {
message.channel.send(`Cannot eject **${mention}**.`);
message.channel.bulkDelete(1);
}
if (mention.roles.cache.find(r => r.name === "dittatore")) return;
message.channel.bulkDelete(1);
const testembed = {
color: '#7A2F8F',
title: 'test',
description: `${mention} this is a test embed`,
footer: 'test footer',
};
let sent = await message.channel.send({ embed: testembed }).then(async (embedMessage) => {
await embedMessage.react('✅');
await embedMessage.react('❌');
});
let id = sent.id; //TypeError: Cannot read property 'id' of undefined
fs.writeFile('/home/pi/botstuff/testembed.txt', id, (err) => {
if (err) throw err;
});
console.log(`wrote ${id} on file`);
const channel = message.guild.channels.cache.get("770735002182877224");
channel.send(`${mention}`);
}
【问题讨论】:
标签: node.js discord discord.js