admin管理员组文章数量:1399788
I saw the post on how to add a cooldown for a twitch bot (cooldown for twitch bot) and the response given by @Ma3x is just what I needed (pasting it here for reference):
// the time of the last help message
let lastHelpTime = 0
client.on('message', (channel, tags, message, self) => {
const send = message === "!help"
if (!send ) return;
// get the current time
const timeNow = new Date().getTime()
// check if at least 1 minute has elapsed since the last help message
if (timeNow - lastHelpTime > 60 * 1000) {
// update the last help message time
lastHelpTime = timeNow
// post the help message in chat
client.say(channel, `This is the help message`)
}
console.log(`${tags['display-name']}: ${message}`);
});
However, it detects the exact word only. How do I make it detect any variation of the word "!help" like "!HELP", "!HeLp" or when it's part of the message like "!help bot chat"?
Thank you!
I saw the post on how to add a cooldown for a twitch bot (cooldown for twitch bot) and the response given by @Ma3x is just what I needed (pasting it here for reference):
// the time of the last help message
let lastHelpTime = 0
client.on('message', (channel, tags, message, self) => {
const send = message === "!help"
if (!send ) return;
// get the current time
const timeNow = new Date().getTime()
// check if at least 1 minute has elapsed since the last help message
if (timeNow - lastHelpTime > 60 * 1000) {
// update the last help message time
lastHelpTime = timeNow
// post the help message in chat
client.say(channel, `This is the help message`)
}
console.log(`${tags['display-name']}: ${message}`);
});
However, it detects the exact word only. How do I make it detect any variation of the word "!help" like "!HELP", "!HeLp" or when it's part of the message like "!help bot chat"?
Thank you!
Share Improve this question asked Mar 24 at 21:19 user26604864user26604864 54 bronze badges1 Answer
Reset to default 0Use the JavaScript .toLowerCase()
function to convert everything in the message to lower-case and .includes()
to check for the matching string in the message when comparing the message to your desired text (read more toLowerCase and includes):
// the time of the last help message
let lastHelpTime = 0
client.on('message', (channel, tags, message, self) => {
const send = message.toLowerCase().includes("!help")
if (!send ) return;
// get the current time
const timeNow = new Date().getTime()
// check if at least 1 minute has elapsed since the last help message
if (timeNow - lastHelpTime > 60 * 1000) {
// update the last help message time
lastHelpTime = timeNow
// post the help message in chat
client.say(channel, `This is the help message`)
}
console.log(`${tags['display-name']}: ${message}`);
});
Example:
console.log("!HELP".toLowerCase().includes("!help"))
console.log("!HeLp".toLowerCase().includes("!help"))
console.log("!help".toLowerCase().includes("!help"))
console.log("!hElp mE Bot".toLowerCase().includes("!help"))
Note: This only checks to see if "!help" is part of the message, and not the -first- part of the message, that would require different logic.
本文标签: htmlAdding variation on trigger word for twitch botStack Overflow
版权声明:本文标题:html - Adding variation on trigger word for twitch bot - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744227978a2596186.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论