-
is it possible to reply message with some condition and respone like, someone message "GM" and the reply is"GM fam", "GM, how u doing?" The point is to be able to reply some of the messages/questions that have been prepared to be answered with our list of answers. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 37 replies
-
{
id()
const search = 'GM'
const channelId = cid
let message = 'GM Fam'
const seenMessagesIds = new Set()
var loop = true
while (loop) {
const messages = await api.getMessages(cid, 100)
const found = messages.filter(msg => msg.content.includes(search) && !seenMessagesIds.has(msg.id))
if (found.length > 0) {
for (const msg of found) {
console.log(`Found message ID=${msg.id} "${msg.content}" by ${msg.author.username}#${msg.author.discriminator} ID=${msg.author.id}`)
seenMessagesIds.add(msg.id)
await api.sendMessage(msg.channel_id, message)
}
}
await api.delay(15000) // wait 15s
}
} Something like this might work, stole the code from another thread posted by OP |
Beta Was this translation helpful? Give feedback.
-
Index with Repeat; {
id()
const userId = "" // Your user id here. Right click and click Copy id to get your id.
const search = ['GM','HI','HELLO']
const channelId = cid
let message = ['GM Fam','Hi there!','Welcome!']
const seenMessagesIds = new Set()
var loop = true
var i = 0;
const welcome = await api.sendMessage(channelId, 'Welcome to our server...')
while (loop) {
const messages = await api.getMessages(cid, null, {limit: 100, after: welcome.id}) // Limits to 100 messages and work after 'welcome' message.
const found = messages.filter(msg => msg.content.includes(search[i]) && !seenMessagesIds.has(msg.id) && msg.author.id != userId )
if (found.length > 0) {
for (const msg of found) {
console.log(`Found message ID=${msg.id} "${msg.content}" by ${msg.author.username}#${msg.author.discriminator} ID=${msg.author.id}`)
seenMessagesIds.add(msg.id)
const sent = await api.replyToMessage(msg.channel_id, msg.id, message[i])
seenMessagesIds.add(sent.id)
}
}
i++;
if (i === search.length) {
i = 0;
}
await api.delay(15*1000) // wait 15s, 1000 is one second. You can edit here.
}
} Index with No-Repeat ( its not repeating bcz index count added if loop true and index not turn to zero ) ; {
id()
const userId = "" // Your user id here. Right click and click Copy id to get your id.
const search = ['GM','HI','HELLO']
const channelId = cid
let message = ['GM Fam','Hi there!','Welcome!']
const seenMessagesIds = new Set()
var loop = true
var i = 0;
const welcome = await api.sendMessage(channelId, 'Welcome to our server...')
while (loop) {
const messages = await api.getMessages(cid, null, {limit: 100, after: welcome.id}) // Limits to 100 messages and work after 'welcome' message.
const found = messages.filter(msg => msg.content.includes(search[i]) && !seenMessagesIds.has(msg.id) && msg.author.id != userId )
if (found.length > 0) {
for (const msg of found) {
console.log(`Found message ID=${msg.id} "${msg.content}" by ${msg.author.username}#${msg.author.discriminator} ID=${msg.author.id}`)
seenMessagesIds.add(msg.id)
const sent = await api.replyToMessage(msg.channel_id, msg.id, message[i])
seenMessagesIds.add(sent.id)
}
}
i++;
await api.delay(15*1000) // wait 15s, 1000 is one second. You can edit here.
}
} No-Index with Repeat ( its repeating bcz code using loop ) ; {
id()
const userId = "" // Your user id here. Right click and click Copy id to get your id.
const search = 'GM'
const channelId = cid
let message = 'GM Fam'
const seenMessagesIds = new Set()
var loop = true
const welcome = await api.sendMessage(channelId, 'Welcome to our server...')
while (loop) {
const messages = await api.getMessages(cid, null, {limit: 100, after: welcome.id}) // Limits to 100 messages and work after 'welcome' message.
const found = messages.filter(msg => msg.content.includes(search) && !seenMessagesIds.has(msg.id) && msg.author.id != userId )
if (found.length > 0) {
for (const msg of found) {
console.log(`Found message ID=${msg.id} "${msg.content}" by ${msg.author.username}#${msg.author.discriminator} ID=${msg.author.id}`)
seenMessagesIds.add(msg.id)
const sent = await api.replyToMessage(msg.channel_id, msg.id, message)
seenMessagesIds.add(sent.id)
}
}
await api.delay(15*1000) // wait 15s, 1000 is one second. You can edit here.
}
} If you wan't to stop write console; loop = false |
Beta Was this translation helpful? Give feedback.
Index with Repeat;