简体   繁体   English

Discord.js v13 无法读取属性 o 未定义的读取发送

[英]Discord.js v13 cannot read properties o undefined reading send

So i have this problem where i wanna make a warn system but it doesnt work!所以我遇到了这个问题,我想制作一个警告系统,但它不起作用! I dont know how to fix it!我不知道如何解决它! I already tried some things to fix it but nothing helped!我已经尝试了一些方法来修复它,但没有任何帮助! Because of that i really appreciate when someone helps me!因此,当有人帮助我时,我真的很感激!

Error Log:错误日志:

[FATAL] Possibly Unhandled Rejection at: Promise  Promise {
  <rejected> TypeError: Cannot read properties of undefined (reading 'roles')
      at Object.run (/home/runner/Bolt-Utilities/Commands/Mod/warn.js:75:48)
      at module.exports (/home/runner/Bolt-Utilities/events/guild/command.js:132:13)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
}  reason:  Cannot read properties of undefined (reading 'roles')

warn.js file: warn.js 文件:


const Discord = require("discord.js");
const ms = require("ms");


module.exports = {
    name: "warn",
    category: "Moderation",
    description: "Warns a user.",
    aliases: [" "],
    usage: "warn <mention> <reason>",
    run: async (client, message, args) => {
    let reason = args.slice(1).join(" ");
    //  const user = message.mentions.users.first();
    const warninguser = message.mentions.users.first();
    const user =
        warninguser ||
        (args[0]
            ? args[0].length == 18
                ? message.guild.members.cache.get(args[0]).user
                : false
            : false);

    const notice1 = new Discord.MessageEmbed()
        .setDescription(
            `<:No:888010623726784512> ${message.author.username}, Missing Permission`
        )
        .setColor("RED");

    const notice3 = new Discord.MessageEmbed()
        .setDescription(`<:No:888010623726784512> I don't have permission to warn people!`)
        .setColor("RED");

    const notice333 = new Discord.MessageEmbed()
        .setDescription(`<:No:888010623726784512> You must mention someone to warn him/her!`)
        .setColor("RED");
if(!message.member.permissions.has('BAN_MEMBERS', 'KICK_MEMBERS')) {
        return message.channel
            .send(notice3)
            .then(m => m.delete({ timeout: 15000 }));
    }
    if(!message.member.permissions.has('KICK_MEMBERS')) {
        return message.channel
            .send(notice1)
            .then(m => m.delete({ timeout: 15000 }));
    }

    if (!user) {
        return message.channel.send({ embeds: [notice333]}
                                )}

    const notice2 = new Discord.MessageEmbed()
        .setDescription(`<:No:888010623726784512> You cannot warn yourself`)
        .setColor("RED");

    if (user.id === message.author.id) {
        return message.channel
            .send(notice2)
            .then(m => m.delete({ timeout: 15000 }));
    }

    if (reason.length < 1) reason = "No reason given.";

    const key = `${message.guild.id}-${user.id}`;

    const dsfdsfsdf = new Discord.MessageEmbed()
        .setDescription(
            `<:No:888010623726784512> Access Denied, that member has roles higher or equal to you!`
        )
        .setColor("RED");
    const sdfsdfsdfsd = new Discord.MessageEmbed()
        .setDescription(
            `<:No:888010623726784512> Access Denied, **that member has roles higher or equal to me!`
        )
        .setColor("RED");
    const botRolePossition = message.guild.member.roles.highest
        .position;
    const rolePosition = message.guild.member.roles.highest.position;
    const userRolePossition = message.member.roles.highest.position;
    if (userRolePossition <= rolePosition) return message.channel.send(dsfdsfsdf);
    if (botRolePossition <= rolePosition)
        return message.channel.send(sdfsdfsdfsd);

    client.moderationdb.ensure(key, {
        guildid: message.guild.id,
        userid: user.id,
        warns: 0,
        isMuted: false,
        timeMuteEnd: 0,
    });
    client.moderationdb.inc(key, "warns");

    const test1 = new Discord.MessageEmbed()
        .setDescription(
            `${emojis.tick} Muted **${user.username}#${user.discriminator}** For 1 Hour | **Reached Two Warnings**`
        )
        .setColor("GREEN");
    const bsuembed = new Discord.MessageEmbed()
        .setDescription(
            `${emojis.tick} Warned **${user.username}#${user.discriminator}** | **${reason}**`
        )
        .setColor("GREEN");

    message.delete();
    message.channel.send(bsuembed);
    user.send(
        `You are warned in **${
            message.guild.name
        }** (Total Warning(s): \`${client.moderationdb.get(
            key,
            "warnings"
        )}\` ), **${reason}**`
    );

    const test2 = new Discord.MessageEmbed()
        .setDescription(
            `<a:yes:934051517986656256> Kicked **${user.username}#${user.discriminator}** | **Reached Warnings 3**`
        )
        .setColor("GREEN");

    const test3 = new Discord.MessageEmbed()
        .setDescription(
            `<a:yes:934051517986656256> Banned **${user.username}#${user.discriminator}** | **Reached 5 Warnings**`
        )
        .setColor("GREEN");

    if (client.moderationdb.get(key, "warns") == 2) {
        const muteRole = client.guilds.cache
            .get(message.guild.id)
            .roles.cache.find(val => val.name === "Muted");

        const mutetime = "60s";
        message.guild.members.cache.get(user.id).roles.add(muteRole.id);
        message.channel.send(test1);

        setTimeout(() => {
            message.guild.members.cache.get(user.id).roles.remove(muteRole.id);
        }, ms(mutetime));
    }

    if (client.moderationdb.get(key, "warns") == 3) {
        message.guild.member(user).kick(reason);
        message.channel.send(test2);
    }

    if (client.moderationdb.get(key, "warns") >= 5) {
        message.guild.member(user).ban(reason);
        message.channel.send(test3);
    }
}
};

I hope someone know the answer!我希望有人知道答案! I will try to say if it worked as fast as possible!我会尝试说它是否尽可能快地工作!

Note: This is written for Discord.js v13.4.0注意:这是为 Discord.js v13.4.0 编写的


<Guild>.member is not a property <Guild>.member不是属性

The first instance of the .roles property being called is on this line.被调用的.roles属性的第一个实例在此行。

const botRolePossition = message.guild.member.roles.highest

The issue is at <Guild>.member .问题出在<Guild>.member You're trying to call .member , which does not exist.您正在尝试调用不存在的.member Assuming you're requesting the bot user, you should use <Guild>.me , which will return a GuildMember that represents the bot in the server.假设您正在请求机器人用户,您应该使用<Guild>.me ,它将返回一个GuildMember代表服务器中的机器人。 Here's what the altered version would look like:更改后的版本如下所示:

// DON'T do this
message.guild.member

// DO this
message.guild.me

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法读取未定义的属性(读取“发送”)(Discord.js v13) - Cannot read properties of undefined (reading 'send') (Discord.js v13) TypeError:无法在 discord.js v13 中读取未定义的属性(读取“路径”) - TypeError: Cannot read properties of undefined (reading 'path') in discord.js v13 discord.js v13 - 类型错误:无法读取未定义的属性(读取“正常运行时间”) - discord.js v13 - TypeError: Cannot read properties of undefined (reading 'uptime') 无法读取未定义的属性(读取“权限”)。 | Discord.js v13 - Cannot read properties of undefined (reading 'permissions'). | Discord.js v13 discord.js v13 类型错误:无法读取未定义的属性(读取“存在”) - discord.js v13 TypeError: Cannot read properties of undefined (reading 'presence') 类型错误:无法读取未定义的属性(读取“设置”)discord.js v13 斜杠命令处理程序 - TypeError: Cannot read properties of undefined (reading 'set') discord.js v13 slash commands handler 类型错误:无法读取未定义的属性(读取“获取”)Discord.js v13 - TypeError: Cannot read properties of undefined (reading 'fetch') Discord.js v13 无法在 Discord.js V13 中读取未定义的属性(读取“删除”) - Cannot read properties of undefined (reading 'delete') in Discord.js V13 discord.js v13 permissions.has() function 不工作(TypeError: Cannot read properties of undefined (reading 'has')) - discord.js v13 permissions.has() function not working (TypeError: Cannot read properties of undefined (reading 'has')) 无法发送空消息 - Discord.JS v13 - Cannot send empty message - Discord.JS v13
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM