【发布时间】:2020-06-05 02:54:37
【问题描述】:
channelBackgroundCheck.send(`${reaction.users.cache.last()}, your account is being reviewed. Please standby.`)
当我运行代码并通过对消息做出反应来执行 if 语句时,它会将其发送到频道 undefined, your account is being reviewed. Please standby. 在我删除反应并再次做出反应后,它正确地提到了我的名字。我已经有 2 个部分,我认为他们会涵盖这个
if (reaction.partial) & if (reaction.message.partial)。最初是否可以正确显示做出反应的用户名?
我正在使用 Discord.js 的主版本。这是我的代码:
if (emoji.name == '✅') {
if (reaction.partial) {
try {
await reaction.fetch();
} catch (error) {
console.log('Something went wrong when fetching the reaction: ', error);
}
}
if (reaction.message.partial) {
// If the message was removed the fetching might result in an API error, which we need to handle
try {
await reaction.message.fetch();
} catch (error) {
console.log('Something went wrong when fetching the message: ', error);
}
}
message.guild.members.fetch(user.id).then(member => {
member.roles.add('679017985905786884');
member.roles.remove('678920391863042048');
const guild = client.guilds.cache.get('678723590631325716')
const channelBackgroundCheck = guild.channels.cache.get('678746066681724928')
channelBackgroundCheck.send(`${reaction.users.cache.last()}, your account is being reviewed. Please standby.`)
const channelFrontexStaff = guild.channels.cache.get('679082070081011773')
channelFrontexStaff.send(`${reaction.users.cache.last()}, has joined the server. Their account is created on ${user.createdAt.toLocaleDateString("nl-NL")}`)
const now = new Date();
now.setMilliseconds(0);
now.setSeconds(0);
now.setMinutes(0);
now.setHours(0);
console.log(now);
const accountCreation = user.createdAt;
accountCreation.setMilliseconds(0);
accountCreation.setSeconds(0);
accountCreation.setMinutes(0);
accountCreation.setHours(0);
console.log(accountCreation);
if(now - accountCreation < (86400000 * 7) /* one day multiplied by desired amount of days */) {
channelFrontexStaff.send(`⚠️ ${reaction.users.cache.last()} has a new account.`)
}
});
}
});
【问题讨论】:
标签: javascript node.js discord discord.js