最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - TypeError: Cannot read properties of undefined (reading 'guild') - Stack Overflow

programmeradmin5浏览0评论

I want to create a reaction role bot but this line

const maths = message.guild.roles.cache.find(role => role.name === "Maths");

puts me this error : TypeError: Cannot read properties of undefined (reading 'guild')

how i can fix this ? Thanks !

index.js :

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"]}, {partials: ["MESSAGE", "CHANNEL", "REACTION"] })
require("dotenv").config();

const prefix = "!";

const fs = require("fs");

clientmands = new Discord.Collection();

const commandFiles = fs.readdirSync("./commands/").filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
    const command = require(`./commands/${file}`);

    clientmands.set(command.name, command);
}

client.on("ready", () => {
    console.log("bot online");
});

client.on("message", message => {

    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();
    if (command === "reactionrole") {
        clientmands.get("reactionrole").execute(message. args, Discord, client);
    }



});

client.login(process.env.BOT_TOKEN);

reactionrole.js :

    name: 'reactionrole',
    description: "Sets up a reaction role message",
    async execute(message, args, Discord, client) {
        const channel = "889087325244629012";
        const maths = message.guild.roles.cache.find(role => role.name === "Maths");
        const mathsExpertes = message.guild.roles.cache.find(role => role.name === "Maths expertes");
        const nsi = message.guild.roles.cache.find(role => role.name === "NSI");
        const physique = message.guild.roles.cache.find(role => role.name === "Physique");
        const svt = message.guild.roles.cache.find(role => role.name === "SVT");
        const artsPlastique = message.guild.roles.cache.find(role => role.name === "Arts Plastiques");

        const mathsEmoji = '
发布评论

评论列表(0)

  1. 暂无评论