英文:
bot to send message to a different channel on same server
问题
我正在尝试让我的Discord机器人在响应中有多个项目时,将消息发送到另一个频道(在同一服务器上)时,这段代码位于一个异步函数内,并返回响应的第一个项目。
目前,这段代码正在发送到命令发起的频道。当我尝试发送到另一个频道时,我会遇到错误,例如找不到“fetch”或找不到“cache”。我漏掉了什么,以使其工作?
if(response.length > 1)
{
let returnMessage = 'Items found: ' + response.length;
for(let i = 0; i < response.length; i++)
{
let responseString = response[i].toString();
returnMessage += "\r\n" + responseString.substring(responseString.indexOf('/', 10));
}
// 在这里发送消息到另一个频道
message.channel.send("测试消息"); // 这会将消息发送到当前频道。
}
英文:
I am trying to get my Discord bot to send a message to another channel when there is more than one item in the response, write a message to another channel (on the same server). This code is within an async function and returns the first item of the response.
Currently, this code is sending to the channel where the command originated. When I attempt things I've found to send to another channel, I get errors such as fetch not being found
or cache not being found
. What am I missing to get this to work?
if(response.length > 1)
{
let returnMessage = 'Items found: " + response.length;
for(let i = 0; i < response.length; i++)
{
let responseString = response[i].toString();
returnMessage += "\r\n" + responseString.substring(responseString.indexOf('/', 10));
}
// send message to another channel here
message.channel.send("test message"); // this sends the message to the current channel.
}
答案1
得分: 0
这是我最终所做的,似乎正在运行。
message.client.channels.cache.get('CHANNEL ID').send('message');
英文:
Here is what I ended up doing, and it appears to be working.
message.client.channels.cache.get('CHANNEL ID').send('message');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论