简体   繁体   English

无法读取未定义的属性(读取“发送”)(Discord.js v13)

[英]Cannot read properties of undefined (reading 'send') (Discord.js v13)

i have been trying to make a leaveserver code for my bot, but i always get the error message Cannot read properties of undefined (reading 'send') I really wanna know why it always says the error messages!我一直在尝试为我的机器人制作一个 leaveserver 代码,但我总是收到错误消息Cannot read properties of undefined (reading 'send')我真的很想知道为什么它总是说错误消息! Please help me!请帮我! Thanks!谢谢!

const Discord = require("discord.js")
const rgx = /^(?:<@!?)?(\d+)>?$/;

var self = this

const OWNER_ID = require("../../config.json").OWNER_ID;
module.exports = {
  name: "leaveserver",
  description: "leavs a server",
  run: async (client, message, args) => {
    if (!OWNER_ID)
      return message.channel.send("This command is Owner Only")},
      
async run(message, args) {
    const guildId = args[0];
    if (!rgx.test(guildId))
    return message.channel.send("Please Provide a valid server id!")
    const guild = message.client.guild.cache.get(guildId);
    if (!guild) return message.channel.send(message, 0, 'Unable to find server, please check the provided ID');
    await guild.leave();
    const embed = new MessageEmbed()
      .setTitle('Leave Guild')
      .setDescription(`I have successfully left **${guild.name}**.`)
      .setFooter(message.member.displayName,  message.author.displayAvatarURL({ dynamic: true }))
      .setTimestamp()
      .setColor(message.guild.me.displayHexColor);
    message.channel.send({embeds: [embed]});
  } 
}

Try this code试试这个代码

const {
    MessageEmbed
} = require("discord.js")
const rgx = /^(?:<@!?)?(\d+)>?$/;
const OWNER_ID = require("../../config.json").OWNER_ID;

module.exports = {
    name: "leaveserver",
    description: "leaves a server",
    run: async (client, message, args) => {
        const guildId = args[0];
        const guild = message.client.guilds.cache.get(guildId);

        if (!OWNER_ID) return message.channel.send("This command is Owner Only");

        if (!rgx.test(guildId)) return message.channel.send("Please Provide a valid server id!")
        if (!guild) return message.channel.send(message, 0, 'Unable to find server, please check the provided ID');

        await guild.leave();
        
        const embed = new MessageEmbed()
            .setTitle('Leave Guild')
            .setDescription(`I have successfully left **${guild.name}**.`)
            .setFooter({
                text: message.member.displayName,
                iconURL: message.author.displayAvatarURL({
                    dynamic: true
                })
            })
            .setTimestamp()
            .setColor(message.guild.me.displayHexColor)
        message.channel.send({
            embeds: [embed]
        })
    }
}

Removed the duplicated async run(message, args) {删除了重复的async run(message, args) {

Try to do this:尝试这样做:

const client = new Discord.Client({intents:
["GUILDS", "GUILD_MESSAGES"]});

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

   await guild.leave();
    const embed = new MessageEmbed()
      .setTitle('Leave Guild')
      .setDescription(`I have successfully left **${guild.name}**.`)
      .setFooter(msg.member.displayName,  msg.author.displayAvatarURL({ dynamic: true }))
      .setTimestamp()
      .setColor(msg.guild.me.displayHexColor);
    msg.channel.send({embeds: [embed]});
})

暂无
暂无

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

相关问题 Discord.js v13 无法读取属性 o 未定义的读取发送 - Discord.js v13 cannot read properties o undefined reading send 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