【发布时间】:2021-07-08 17:23:12
【问题描述】:
我正在发出一个命令,通过向他们发送一个 dm 来对提到的用户进行 rickroll,当我尝试通过提及使用他们的 ID 的人来使用它时,它不起作用并发送我添加的错误消息:The mentioned user is not in the server
const { DiscordAPIError } = require('discord.js');
const Discord = require('discord.js');
const BaseCommand = require('../../utils/structures/BaseCommand');
module.exports = class RickrollCommand extends BaseCommand {
constructor() {
super('rickroll', 'fun', []);
}
async run(client, message, args) {
let mentionedMember = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
if (!args[0]) return message.channel.send('You need to mention a member to rickroll.');
if (!mentionedMember) return message.channel.send('The user mentioned is not in the server.');
if (mentionedMember.user.id == client.user.id) return message.channel.send('You really thought i was boutta rickroll myself? AINT NO WAY CHEIF');
const rickrollEmbed = new Discord.MessageEmbed()
.setTitle("You've Been Rickrolled!")
.setThumbnail('https://i1.wp.com/my-thai.org/wp-content/uploads/rick-astley.png?resize=984%2C675&ssl=1')
.setDescription('Rick astley sends his regards')
.setColor('#FFA500');
await mentionedMember.send('https://tenor.com/view/dance-moves-dancing-singer-groovy-gif-17029825')
await mentionedMember.send(rickrollEmbed)
.then(() => {
message.channel.send("Successfully rickrolled the user.");
})
.catch(err => {
message.channel.send('I was unable to rickroll the user.');
});
}
}
奇怪的是它只适用于我的 ID,而不适用于任何其他用户的 ID。
【问题讨论】:
-
我认为问题在于,当使用用户 ID 时,您无法检索带有提及的用户,因此它会尝试从缓存中获取它,但缓存中唯一的用户是您的.因此它不会找到任何其他用户
标签: javascript discord discord.js bots