首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用关键字向特定的不和谐频道发送消息?

如何使用关键字向特定的不和谐频道发送消息?
EN

Stack Overflow用户
提问于 2020-12-30 07:08:52
回答 1查看 97关注 0票数 0

目前,我的bot将接受使用!wts命令的任何消息,并将消息镜像到指定的通道(在代码中设置)。

如果消息包含" UK8“,它将被发送到UK8通道,或者如果它包含" UK3.5”,它将被发送到UK3.5通道,因此它将查找关键字并将消息分配给相应的通道(而不是像我所做的那样对其进行硬编码)。

我刚刚开始学习不一致的botting,所以我很感谢大家的帮助。

这是我到目前为止所知道的:

代码语言:javascript
复制
    client.on('message', message => {

    if (message.author.bot) return undefined //bot does not reply to itself
  
    let msg = message.content.toLowerCase()
    let args = message.content
      .slice(prefix.length)
      .trim()
      .split(' ') //arguments
    let command = args.shift().toLowerCase() //shifts args to lower case letters
  
    if (command === 'wts') {
      let say = args.join(' ') //space
      //message.delete() - remove // if you want to have each message deleted
      const generalChannel = message.guild.channels.cache.get('793494585123465875')
      generalChannel.send(message.author.toString() + ": " + say)

    }
EN

回答 1

Stack Overflow用户

发布于 2020-12-30 10:41:00

代码语言:javascript
复制
let nameChannel = "";

if(say.includes("uk8")){
    nameChannel = "UK8";
}else if(say.includes("uk3.5")){
    nameChannel = "uk3.5";
}else{
    nameChannel = "defaultChannel";
}

const selectedChannel = client.channels.cache.find(channel => channel.name === nameChannel );
selectedChannel.send(say)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65499951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档