将消息发送到同一服务器上的不同频道的机器人

huangapple go评论56阅读模式
英文:

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 &gt; 1)
{
  let returnMessage = &#39;Items found: &quot; + response.length;

  for(let i = 0; i &lt; response.length; i++)
  {
    let responseString = response[i].toString();
    returnMessage += &quot;\r\n&quot; + responseString.substring(responseString.indexOf(&#39;/&#39;, 10));
  }

  // send message to another channel here
  message.channel.send(&quot;test message&quot;); // 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(&#39;CHANNEL ID&#39;).send(&#39;message&#39;);

huangapple
  • 本文由 发表于 2023年5月25日 10:55:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76328617.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定