简体   繁体   English

如何让我的 discord 机器人回复包含特定字母/字符的消息?

[英]How can I make my discord bot reply to a message when it contains a specific letter/character?

So basically, I want my bot to reply to people who input commands for other bots, for example when they type -p(play) (insert song here) I don't want my bot to play a song but instead I want it to reply to them just as when people like to give their thoughts on someone's opinion with a variety of answers.所以基本上,我希望我的机器人回复为其他机器人输入命令的人,例如当他们输入 -p(play) (在此处插入歌曲)时,我不希望我的机器人播放歌曲,而是希望它播放回复他们就像人们喜欢用各种各样的答案来表达他们对某人意见的看法一样。 I already input a command where it replies to people when they write $w but what I want is for my bot to reply when they put something else after $w.我已经输入了一个命令,当人们写 $w 时它会回复他们,但我想要的是让我的机器人在他们在 $w 之后添加其他内容时回复。

const replies = [
    "nice", "I like it", "We have the same tastes", "lucky!", "I wish I were you",
]

client.on("message", gotMessage);

async function gotMessage(msg) {

    if (msg.content === "$w"){
        const index = Math.floor(Math.random() * replies.length);
        msg.channel.send(replies[index]);
     }
}

So if I understand correctly, you want to check if a word is in the message.因此,如果我理解正确,您想检查消息中是否包含单词。 To do so you can use the String.includes() .为此,您可以使用String.includes()

if (msg.content.includes("$w"){
    //do stuff
}

EDIT:编辑:

You could also check if the message starts with it您还可以检查消息是否以它开头

if(msg.content.startsWith("$w")){
//do stuff
}```

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让我的 discord 机器人通过回复池回复特定消息? - How do I make my discord bot reply to a specific message with reply from a pool of replies? 当被问到某个问题时,如何让我的 Discord Bot (Javascript) 在标签中回复用户? - How can i make my Discord Bot (Javascript) reply to the user in tag, when a certain question is asked? 我怎样才能让机器人回复一条由我不和谐的回复的消息 - How can i make the bot reply to a message which is a reply by me discord 如何让 discord 机器人检查消息的内容并根据作者回复不同的消息? - How can I make a discord bot check the contents of a message and reply with a different message depending on the author? 当特定用户玩特定游戏时,如何让我的不和谐机器人发送消息? - How do I make my discord bot send a message when a specific user plays a specific game? 如何让我的 discord 机器人仅在用户开始输入特定频道时发送消息? - How can I make my discord bot only send a message if a user starts typing in a specific channel? 如何使Discord bot DM用户获得特定答复? - How do I make my Discord bot DM users with a specific reply? 如何让我的 Discord Bot 回复并提及? - How to make my Discord Bot reply with a mention? 如何使 Telegram BOT 回复特定消息? - How to make Telegram BOT reply to a specific message? 我想让我的 discord 机器人能够使用包含输入用户名的链接的用户名回复命令 - I want to make my discord bot be able to reply to a command with a username with a link that contains the inputted username
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM