GoatSniff
GoatSniff
DIAdiscord.js - Imagine an app
Created by GoatSniff on 8/22/2023 in #djs-questions
Guild Member cache doesn't contain all users
Looks like it's all working, thanks
17 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 8/22/2023 in #djs-questions
Guild Member cache doesn't contain all users
I don't even want to explain how I managed to confuse that
17 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 8/22/2023 in #djs-questions
Guild Member cache doesn't contain all users
Sorry... False alarm 😅
17 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 8/22/2023 in #djs-questions
Guild Member cache doesn't contain all users
Hmm now I have a new issue
const guild = await client.guilds.cache.get(process.env.DISCORD_GUILD_ID);
await guild.members.fetch()
const member = await guild.members.cache.get(discordID);
console.log(guild.members.cache) // Shows Collection(2) with my bot twice
const guild = await client.guilds.cache.get(process.env.DISCORD_GUILD_ID);
await guild.members.fetch()
const member = await guild.members.cache.get(discordID);
console.log(guild.members.cache) // Shows Collection(2) with my bot twice
After doing a fetch, my cache contains two users. But both of them are the bot itself and it still doesn't contain my user
17 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 8/22/2023 in #djs-questions
Guild Member cache doesn't contain all users
Thanks I'll give it a go
17 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 8/22/2023 in #djs-questions
Guild Member cache doesn't contain all users
Ah okay
17 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 8/22/2023 in #djs-questions
Guild Member cache doesn't contain all users
It throws an error if there's nothing new fetched?
17 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 8/22/2023 in #djs-questions
Guild Member cache doesn't contain all users
If I understand correctly, I can fetch() to get all users, then the cache should be up to date enough that I can trust it to contain all the data present at the time of the fetch?
17 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
Okay I figured this out. The example I gave you from the docs wasn't "true to life" as all I wanted to do was have a button with a URL which doesn't require any special interaction handling logic since it's just a button with a URL The core issue was just that I didn't import the ButtonBuilder, ButtonStyle, etc and I was catching all the errors which I didn't realise so I never saw the true cause. All fixed now, thanks all for your help 👍
16 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
Is that typescript specific?
16 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
That'd be it then :D, I didn't know there was special handling needed but I will have a look through the docs
16 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
I'll log that error out, one second
16 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
I guess that explains my error message 😅 Forgot I even added that
16 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
const { Events } = require('discord.js');
const config = require('../configs/config.json');

const timers = [];

function beginRateLimitTimer(userID) {
timers.push({ userID, timer: setTimeout(endRateLimitTimer, config.rateLimitMS, userID) })
}

// Called when rate limit timer is reached
function endRateLimitTimer(userID) {
const index = timers.findIndex(t => t.userID === userID);
if (index !== -1) {
timers.splice(index, 1);
}
}

function isRateLimited(userID) {
return timers.some(t => t.userID == userID);
}

module.exports = {
name: Events.InteractionCreate,
once: false,
async execute(interaction) {
if (isRateLimited(interaction.user.id)) {
return await interaction.reply({ content: `Please wait before using another slash command.`, ephemeral: true });
}

if (interaction.isCommand()) {
const slashCommand = interaction.client.slashCommands.get(interaction.commandName);
if (!slashCommand) return;

beginRateLimitTimer(interaction.user.id);

try {
await slashCommand.execute(interaction);
} catch (err) {
await interaction.reply({ content: `An error has occured.`, ephemeral: true });
}
}
},
};
const { Events } = require('discord.js');
const config = require('../configs/config.json');

const timers = [];

function beginRateLimitTimer(userID) {
timers.push({ userID, timer: setTimeout(endRateLimitTimer, config.rateLimitMS, userID) })
}

// Called when rate limit timer is reached
function endRateLimitTimer(userID) {
const index = timers.findIndex(t => t.userID === userID);
if (index !== -1) {
timers.splice(index, 1);
}
}

function isRateLimited(userID) {
return timers.some(t => t.userID == userID);
}

module.exports = {
name: Events.InteractionCreate,
once: false,
async execute(interaction) {
if (isRateLimited(interaction.user.id)) {
return await interaction.reply({ content: `Please wait before using another slash command.`, ephemeral: true });
}

if (interaction.isCommand()) {
const slashCommand = interaction.client.slashCommands.get(interaction.commandName);
if (!slashCommand) return;

beginRateLimitTimer(interaction.user.id);

try {
await slashCommand.execute(interaction);
} catch (err) {
await interaction.reply({ content: `An error has occured.`, ephemeral: true });
}
}
},
};
16 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
My mistake, one second
16 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
I'd have thought loading shouldn't be the issue since replying with a string is working without a hitch?
16 replies
DIAdiscord.js - Imagine an app
Created by GoatSniff on 7/24/2023 in #djs-questions
Interaction replying with string works but doesn't work when I return a button
App.js
client.slashCommands = new Collection();
const slashCommands = [];

const commandSlashFiles = fs.readdirSync('./commands').filter(file => file.endsWith(".js"));

// Load all slash commands from ./commands
for (const fileSlash of commandSlashFiles) {
const commandSlash = require(`./commands/${fileSlash}`);
client.slashCommands.set(commandSlash.data.name, commandSlash);
slashCommands.push(commandSlash.data.toJSON());
console.log(`${commandSlash.data.name}.js has loaded.`);
}
client.slashCommands = new Collection();
const slashCommands = [];

const commandSlashFiles = fs.readdirSync('./commands').filter(file => file.endsWith(".js"));

// Load all slash commands from ./commands
for (const fileSlash of commandSlashFiles) {
const commandSlash = require(`./commands/${fileSlash}`);
client.slashCommands.set(commandSlash.data.name, commandSlash);
slashCommands.push(commandSlash.data.toJSON());
console.log(`${commandSlash.data.name}.js has loaded.`);
}
Then in my sync.js (the name of my slashcommand)
module.exports = {
data: new SlashCommandBuilder()
.setName('sync')
.setDescription('Sync your account!'),
async execute(interaction) {
// etc....
module.exports = {
data: new SlashCommandBuilder()
.setName('sync')
.setDescription('Sync your account!'),
async execute(interaction) {
// etc....
16 replies