你好,我创建了一个小的抽搐机器人,我希望每100秒钟只执行一次以下条件,例如:
if (message.indexOf("emoji") !== -1) {
client.say(channel, `emoji party`);
}但你可以看到,我有其他类似的条件,所以我不希望我的整个机器人被模仿100秒钟。我希望每个条件都是独立于时间的
const tmi = require("tmi.js");
const client = new tmi.Client({
options: { debug: true, messagesLogLevel: "info" },
connection: {
reconnect: true,
secure: true
},
// Lack of the identity tags makes the bot anonymous and able to fetch messages from the channel
// for reading, supervison, spying or viewing purposes only
identity: {
username: `${process.env.TWITCH_BOT_USERNAME}`,
password: `oauth:${process.env.TWITCH_OAUTH_TOKEN}`
},
channels: ["channelName"]
});
client.connect().catch(console.error);
client.on("message", (channel, tags, message, self) => {
if (self) return;
if (message.indexOf("emoji") !== -1) {
client.say(channel, `emoji party`);
}
if (message.indexOf("LUL") !== -1) {
client.say(channel, `LUL LUL LUL LUL`);
}
});谢谢你的帮助
发布于 2022-07-22 23:28:41
我想这样的东西会对你有用的。我不知道如何存储持久变量,但global可能还可以。
global.lastEmojiPartyMs = null; // lets store last called time (milliseconds)
client.on("message", (channel, tags, message, self) => {
if (self) return;
if (message.indexOf("emoji") !== -1) {
const nowMs = Date.now();
if (
!global.lastEmojiPartyMs ||
nowMs - global.lastEmojiPartyMs >= 100 * 1000 // 100 seconds for example
) {
global.lastEmojiPartyMs = nowMs;
client.say(channel, `emoji party`);
}
}
if (message.indexOf("LUL") !== -1) {
client.say(channel, `LUL LUL LUL LUL`);
}
});https://stackoverflow.com/questions/73086856
复制相似问题