【问题标题】:Unable to send the embeded message in discord.js无法在 discord.js 中发送嵌入消息
【发布时间】:2022-01-25 23:38:33
【问题描述】:

我正在尝试向频道发送公告,但收到此错误:

TypeError: Cannot read properties of undefined (reading 'send')

脚本:

const Discord = require("discord.js");
const clients = new Discord.Client({ intents: 14087});
const allow = require("./admin/announceAllow.json")
module.exports = {
    name: 'announce',
    description: "announce stuff to announcement server",
    execute(message, args, cmdName, extraString, status, reason,user,id, prefix,lang){
        if(cmdName == ""){
            let err = new Discord.MessageEmbed()
            .setTitle("There was an error while announcing")
            .setDescription("Reason: `Empty string`")
            .setColor("RED")
            message.channel.send({embeds:[err]})
        }else
        if(!(cmdName == "")){
        var toAnnounce = cmdName.replace("announce ","")
        var toSend = "929580453554434089"
        var splitToAnnounce = toAnnounce.split(",,")
        console.log(`${splitToAnnounce[0].replace("|n", "\n")}\n${splitToAnnounce[1].replace("|n", "\n")}\n${splitToAnnounce[2].replace("|n", "\n")}`)
        if(allow[message.author.id + ""]){
            try{
                let announce = new Discord.MessageEmbed()
                .setTitle(`${splitToAnnounce[0].replace("|n", "\n")}`)
                .setDescription(`${splitToAnnounce[1].replace("|n", "\n")}`)
                .setColor(`${splitToAnnounce[2].replace("|n", "\n")}`)
                clients.channels.cache.get(`${toSend}`).send({embeds:[announce]})
            }catch(e){
                let err = new Discord.MessageEmbed()
                .setTitle("There was an error while announcing")
                .setDescription("Possible reason: `Bot don't have permission, bot script outdated, bot error, user input error, color error`\n\nUsage: <prefix> announce `title,,content,,color`\ntip: use `|n` for new line\ncolor: `RED,BLUE,GREEN` etc")
                .setColor("RED")
                message.channel.send({embeds:[err]}) 
                console.log(e)   
            }
        }else
        if(!(allow[message.author.id + ""])){...........

请大家解释一下为什么会出现这个错误以及如何解决它

【问题讨论】:

  • 哇,你有很多争论......它们的顺序是否正确?这个错误到底发生在哪里?
  • 嗯,是的,他们是对的,我检查了三次

标签: javascript node.js discord.js


【解决方案1】:

检查toSend 中的频道ID。 我重新创建了此代码的简单版本,并且在错误地输入频道 ID 时能够得到相同的错误。如果您的命令处理程序工作正常,则问题主要出在clients.channels.cache.get... 部分。 在 TypeError 上方,它应该向您显示发生错误时正在运行的代码行。

【讨论】:

    猜你喜欢
    • 2020-10-09
    • 2021-12-01
    • 2021-08-22
    • 2021-04-26
    • 2021-06-25
    • 2021-05-08
    • 2022-08-04
    • 2017-10-31
    • 2020-01-25
    相关资源
    最近更新 更多