Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 向通道发送嵌入/消息时,返回未定义的_Javascript_Discord_Discord.js_Undefined - Fatal编程技术网

Javascript 向通道发送嵌入/消息时,返回未定义的

Javascript 向通道发送嵌入/消息时,返回未定义的,javascript,discord,discord.js,undefined,Javascript,Discord,Discord.js,Undefined,所以我有我为reactionrole设置编写的代码,我想让它转到“845711730809503744”,但返回的是未定义的。 完整代码: client.channels.cache.get(channel => channel.id === "845711730809503744").send(roleEmbed) 有人知道为什么以及如何解决此问题吗?首先,确保ID正确。那就试试看频道fetch从Discord或通道缓存(如果已经可用)获取通道 client.cha

所以我有我为reactionrole设置编写的代码,我想让它转到“845711730809503744”,但返回的是未定义的。 完整代码:

client.channels.cache.get(channel => channel.id === "845711730809503744").send(roleEmbed)

有人知道为什么以及如何解决此问题吗?

首先,确保ID正确。那就试试看频道
fetch
从Discord或通道缓存(如果已经可用)获取通道

client.channels
.fetch(“845711730809503744”)
.then(channel=>channel.send(roleEmbed))
.catch(console.error)
也可以使用异步/等待:

试试看{
const channel=wait client.channels.fetch(“845711730809503744”)
频道发送(roleEmbed)
}捕获(错误){
控制台错误(错误)
}
试试这个

const channel = client.channels.resolve('ID');
channel.send('ooh this is a message');

嗯,我尝试了“fetch”方法,结果返回:
HTTPError[DiscordjsError]:请求使用令牌,但令牌对客户端不可用。
,我认为这是“客户端”的问题?不确定代码的外观,但这需要在事件侦听器中。错误消息可能表示您试图在bot登录之前发出HTTP请求。
const channel = client.channels.resolve('ID');
channel.send('ooh this is a message');