Verena
Verena
DIAdiscord.js - Imagine an app
Created by Verena on 9/7/2024 in #djs-questions
entitlementCreate triggers twice
Hello, I need help This code triggers twice as soon as I create a Test Entitlement via the REST API in Postman, is it because it is a Test Entitlement or should I approach this differently? The code is in my Bot.js outside of the client.on(ready) if important
client.on('entitlementCreate', async (entitlement) => {
logger.info(`New entitlement created for guild ${entitlement.guildId}`);

entitlementCache.set(entitlement.guildId, {
userId: entitlement.userId,
startsTimestamp: entitlement.startsTimestamp,
endsTimestamp: entitlement.endsTimestamp,
deleted: entitlement.deleted
});

const guildData = {
id: entitlement.guildId,
entitlement: {
userId: entitlement.userId,
startsTimestamp: entitlement.startsTimestamp,
endsTimestamp: entitlement.endsTimestamp,
deleted: entitlement.deleted
}
};
await insertEntitlement(guildData);
});
client.on('entitlementCreate', async (entitlement) => {
logger.info(`New entitlement created for guild ${entitlement.guildId}`);

entitlementCache.set(entitlement.guildId, {
userId: entitlement.userId,
startsTimestamp: entitlement.startsTimestamp,
endsTimestamp: entitlement.endsTimestamp,
deleted: entitlement.deleted
});

const guildData = {
id: entitlement.guildId,
entitlement: {
userId: entitlement.userId,
startsTimestamp: entitlement.startsTimestamp,
endsTimestamp: entitlement.endsTimestamp,
deleted: entitlement.deleted
}
};
await insertEntitlement(guildData);
});
3 replies
DIAdiscord.js - Imagine an app
Created by Verena on 2/1/2024 in #djs-questions
Queue to prevent rate limit, but sometimes unreliable. Are there any alternatives or improvements?
Hello, I have written a bot that should make it possible to react to a message with embed for a certain time event and the first 10 are entered in the list and later assigned to a role. This kind of bot also works and I never had problems with it, except now because it can be that too many people react at the same time or one after the other and it comes to a rate limit, this problem has already been solved as well as possible with the queue but it doesn't seem very reliable to me but I get told by people that there are often more than 10 people in this list and I have no idea how to fix it, I'm not very familiar with queues and I'm not the best developer, do any of you have any ideas on how to fix this maybe a different way than the queue or some suggestions on how to improve my code would be greatly appreciated. I have added comments to make it easier to explain. Here is the code for adding people and if anyone wants to remove themselves: - https://hastebin.com/share/ajutuconuy.javascript * https://hastebin.com/share/uradumimef.javascript Thanks in advance.
4 replies
DIAdiscord.js - Imagine an app
Created by Verena on 8/3/2022 in #djs-questions
Get the options as array from interactions.options
Hello, when i sends the interactions.options to the console i get
2|Krautz | CommandInteractionOptionResolver {
2|Krautz | _group: null,
2|Krautz | _subcommand: 'gelagert',
2|Krautz | _hoistedOptions: [
2|Krautz | { name: 'diamant', type: 4, value: 1 },
2|Krautz | { name: 'kürbis', type: 4, value: 12 },
2|Krautz | { name: 'ananas', type: 4, value: 123 }
2|Krautz | ]
2|Krautz | }
2|Krautz | CommandInteractionOptionResolver {
2|Krautz | _group: null,
2|Krautz | _subcommand: 'gelagert',
2|Krautz | _hoistedOptions: [
2|Krautz | { name: 'diamant', type: 4, value: 1 },
2|Krautz | { name: 'kürbis', type: 4, value: 12 },
2|Krautz | { name: 'ananas', type: 4, value: 123 }
2|Krautz | ]
2|Krautz | }
How can i only get the _joistedOptions as output?
6 replies
DIAdiscord.js - Imagine an app
Created by Verena on 7/31/2022 in #djs-questions
Last message will not get deleted
async function fetchAllMessages(chan) {
const channel = client.channels.cache.get(chan);
let messages = [];

// Create message pointer
let message = await channel.messages
.fetch({ limit: 1 })
.then(messagePage => (messagePage.size === 1 ? messagePage.at(0) : null));

while (message) {
await channel.messages
.fetch({ limit: 100, before: message.id })
.then(messagePage => {
messagePage.forEach(msg => {
messages.push(msg)
msg.delete()
});

// Update our message pointer to be last message in page of messages
message = 0 < messagePage.size ? messagePage.at(messagePage.size - 1) : null;
})
}
}
async function fetchAllMessages(chan) {
const channel = client.channels.cache.get(chan);
let messages = [];

// Create message pointer
let message = await channel.messages
.fetch({ limit: 1 })
.then(messagePage => (messagePage.size === 1 ? messagePage.at(0) : null));

while (message) {
await channel.messages
.fetch({ limit: 100, before: message.id })
.then(messagePage => {
messagePage.forEach(msg => {
messages.push(msg)
msg.delete()
});

// Update our message pointer to be last message in page of messages
message = 0 < messagePage.size ? messagePage.at(messagePage.size - 1) : null;
})
}
}
Hello! I use this function to clear a channel but he always not delete the last message that was posted in the channel why?
4 replies
DIAdiscord.js - Imagine an app
Created by Verena on 7/29/2022 in #djs-questions
messages fetch doesnt show up older messages
Hello! I run into a problem with my code:
async function fetchAllMessages(input, interactionUser) {
const channel = client.channels.cache.get(input);
let messages = [];
let amountPayout = 0

// Create message pointer
let message = await channel.messages
.fetch({ limit: 1 })
.then(messagePage => (messagePage.size === 1 ? messagePage.at(0) : null));

while (message) {
await channel.messages
.fetch({ limit: 100, before: message.id })
.then(messagePage => {
messagePage.forEach(msg => {
if (msg.embeds[0] && msg.embeds[0].title != 'Krautz - Familienkasse') {
let receivedEmbed = msg.embeds[0]
const descr = receivedEmbed.description.split(" ");
let id = descr[2].replace("<@", "").replace(">", "")
const user = client.users.cache.get(id)
for (let field of receivedEmbed.fields) {
if (field.name == ":moneybag: Auszahlung" && user == interactionUser) {
let int = parseInt(field.value.replace("$ ", ""))
amountPayout = amountPayout + int
console.log("+ " + int + " Fisch: " + amountPayout)

msg.delete()
}
}
}
//messages.push(msg)
});

// Update our message pointer to be last message in page of messages
message = 0 < messagePage.size ? messagePage.at(messagePage.size - 1) : null;
})
}
return amountPayout
}
async function fetchAllMessages(input, interactionUser) {
const channel = client.channels.cache.get(input);
let messages = [];
let amountPayout = 0

// Create message pointer
let message = await channel.messages
.fetch({ limit: 1 })
.then(messagePage => (messagePage.size === 1 ? messagePage.at(0) : null));

while (message) {
await channel.messages
.fetch({ limit: 100, before: message.id })
.then(messagePage => {
messagePage.forEach(msg => {
if (msg.embeds[0] && msg.embeds[0].title != 'Krautz - Familienkasse') {
let receivedEmbed = msg.embeds[0]
const descr = receivedEmbed.description.split(" ");
let id = descr[2].replace("<@", "").replace(">", "")
const user = client.users.cache.get(id)
for (let field of receivedEmbed.fields) {
if (field.name == ":moneybag: Auszahlung" && user == interactionUser) {
let int = parseInt(field.value.replace("$ ", ""))
amountPayout = amountPayout + int
console.log("+ " + int + " Fisch: " + amountPayout)

msg.delete()
}
}
}
//messages.push(msg)
});

// Update our message pointer to be last message in page of messages
message = 0 < messagePage.size ? messagePage.at(messagePage.size - 1) : null;
})
}
return amountPayout
}
Its working good, but when there are older messages with embeds they don't add them why?
14 replies