繁体   English   中英

无法在 discord.js 中发送嵌入消息

[英]Unable to send the embeded message in discord.js

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

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 + ""])){...........

任何人,请解释为什么会发生此错误以及如何解决它

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM