【发布时间】:2021-12-19 21:14:15
【问题描述】:
我想创建一个白名单角色来执行命令,我输入了这一行
if (!message.guild.cache.roles.find(role => role.id === '873595824469344256')) return;
我得到的错误:Uncaught TypeError: Cannot read properties of undefined (reading 'roles')
const Discord = require("discord.js");
const { Client, Intents } = require('discord.js');
const bot = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "DIRECT_MESSAGE_TYPING", "GUILD_MEMBERS", "GUILD_PRESENCES"] });
const config = require('./config.json');
const prefix = "g!"
bot.on("ready", () => {
console.log(`${bot.user.tag} bot is online`);
});
bot.on("messageCreate", message => {
if(message.content === prefix + "help") {
if (!message.guild.cache.roles.find(role => role.id === '873595824469344256')) return;
let helpembed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Help Guide')
.setAuthor('Request : ' + `${message.author.username}`)
.addFields(
{ name: 'Ban Usage', value: `${prefix}ban **id** | **reason** | **time** \n**__Exemple__** : ${prefix}ban id ALT-F4+Troll (without espace) 32H`},
{ name: 'Warn Usage', value: `${prefix}warn **id** | **reason** | **time** \n**__Exemple__** : ${prefix}warn id Bunny-Hope (without espace) warn-1/2/3`},
)
.setFooter('© ©');
message.reply({ embeds: [helpembed] });
};
});
【问题讨论】:
-
message.guild.cache.roles.find应该是message.guild.roles.cache.find
标签: javascript node.js discord discord.js