繁体   English   中英

类型错误:无法读取 discord.js 中未定义的属性(读取“发送”)

[英]TypeError: Cannot read properties of undefined (reading 'send') in discord.js

我正在尝试将消息发送到 discord 上的特定频道,但出现此错误:

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

不过我输入了正确的频道 ID,可能是什么问题? 这是我的 function 代码和快照:

function discordsend(usern)
{ 
    usern="someusername#1234"
    string = "somethingsomething"+usern;
    const channel = client.channels.cache.get('946932969359179786');
    channel.send(string);
}

在此处输入图像描述

你应该使用client.guilds.cache.get("guild ID").channels.cache.get("channel ID")

如果通道一开始不存在,也可以使用条件链接来避免出错。

暂无
暂无

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

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