【问题标题】:make discord bot to send message specific channel使不和谐机器人发送消息特定通道
【发布时间】:2020-12-18 01:08:34
【问题描述】:

我想做这样的机器人命令:

我在聊天中写:~msg (Text) (Channel),然后机器人会发送一条消息,例如:Hello everyone. (In channel General)

这是我目前使用的代码:

switch (args[0]) {
 case 'msg':

if (!args[1]) return message.channel.send('Fill the channel name')
            if (!args[2]) return message.channel.send('Fill the text')
            message.client.channels.cache.find(channel => channel.name === args[1]).send(args[2]);

    }
})

【问题讨论】:

标签: javascript node.js discord discord.js


【解决方案1】:

您可以使用.find() 方法按名称获取频道,然后使用.send() 方法向那里发送消息。

message.client.channels.cache.find(channel => channel.name === chanArgs).send(msgArgs)

【讨论】:

  • message.client??
  • 任何client 对象都可以。例如,如果你写了const client = new Discord.Client(),那么你可以直接使用client.channels...
  • TypeError: 无法读取未定义的“发送”属性,我认为这几乎是正确的
  • 这只是意味着它无法通过提供的名称找到频道。确保 chanArgs 是有效的频道名称。
  • 感谢它的工作原理,但是当我输入第三个参数时它没有显示出来。你有解决方案吗?所以你可以这样写。我只是编辑代码你可以检查它@Lioness100
猜你喜欢
  • 2021-04-11
  • 2021-08-14
  • 2021-06-17
  • 1970-01-01
  • 2021-04-09
  • 2022-11-02
  • 2019-07-11
  • 2021-04-03
  • 2019-12-10
相关资源
最近更新 更多