我想制作这样的bot命令:
我在聊天中写道:~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]);
}
})
您可以使用.find()
方法按名称获取通道,然后使用.send()
方法简单地向那里发送消息。
message.client.channels.cache.find(channel => channel.name === chanArgs).send(msgArgs)