【问题标题】:discord.js send message on specific channeldiscord.js 在特定频道上发送消息
【发布时间】:2021-10-19 21:14:08
【问题描述】:

我想在特定频道上发送消息。但问题是我的命令应该是这样的 +post CHANNELID message 然后它会在这个频道上发布我已经放置了 id 的消息。 那么有人可以帮我做吗?

example command I want

【问题讨论】:

标签: discord discord.js bots


【解决方案1】:

这其实很简单。您需要做一些事情。

  1. 分离参数
  2. 使用第一个参数 (id) 查找频道
  3. 向频道发送消息,其中包含空格连接的其他参数的内容

这是您的命令的工作示例

client.on("message", msg => {
  const args = msg.content.split(' ');
  const [, chanId, ...message] = args;
  const channel = msg.guild.channels.resolve(chanId);
  channel.send(message.join(" "))
})

【讨论】:

  • 还是不行吗?你解决了吗?
  • 不,我不能:(你能帮我@MrMythical
  • 您遇到错误了吗?什么都没有发生?
猜你喜欢
  • 2021-08-21
  • 2020-04-04
  • 2021-08-09
  • 2020-05-22
  • 2022-01-25
  • 2020-06-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多