#How to defined set??
1 messages · Page 1 of 1 (latest)
are they now still undefined?
because now it is foreach...
help.aliases is undefined, though is different code compared to the other one
i had changed with client.aliases = new Collection(); in my index.js and now in stead of set they say foreach undefined xd. So I am thinking how to fix this
well, this is the 3rd problem you're telling me
you could use console.log just before suspected code and convince yourself that it is indeed undefined
also, if you want to show me more code, post it, don't just talk about it
fs.readdirSync('./commands/').forEach(dir => {
fs.readdir(`./commands/${dir}`, (err, files) => {
if (err) throw err;
var jsFiles = files.filter(f => f.split(".").pop() === 'js');
jsFiles.forEach(file => {
var fileGet = require(`./commands/${dir}/${file}`);
try {
client.commands.set(fileGet.help.name, fileGet);
fileGet.help.aliases.forEach(alias => {
client.aliases.set(alias, fileGet.help.name);
})
} catch (err) {
return console.log(err);
};
})
})
})
This is my cmd handler
const discord = require("discord.js");
module.exports.run = async (client, message, args) => {
var botEmbed = new discord.MessageEmbed()
.setTitle("Botinfo")
.setColor("#0fbfab")
.addFields(
{ name: "Bot naam", value: client.user.username },
{ name: "Gemaakt door", value: "@Daniël#5215" },
{ name: "Aantal servers", value: client.guilds.cache.size.toString() },
// { name: "Aantal leden in alle servers bij elkaar", value: },
)
.setThumbnail("https://cdn.discordapp.com/avatars/730445459159777350/ceeef5f206851463879f667b7ef23c29.png?size=128")
//.setImage("https://zeroserenity.com/wp-content/uploads/2019/07/Discord-Logo-Red.png")
.setFooter("Bot is gemaakt door @Daniël#5215") //, "https://zeroserenity.com/wp-content/uploads/2019/07/Discord-Logo-Red.png")
.setTimestamp();
return message.channel.send({ embeds: [botEmbed] });
}
module.exports.help = {
name: "botinfo",
aliases: ['b'],
}
```This is for example my botinfo.js
I still don't know how to fix the error 😦
ah I have fixed this
Only I have one error more
thx
at line 80, dir is botinfo.js, which is not a directory
yes
i took a fast look at readdirSync, and it DOES NOT returns only directories, but files too
you're trying to read a file as a directory, which is wrong
oh lol, I think I just have to make a folder in my slashcommands folder....
omg
yess
It works....
you do, and you also have to NOT HAVE any files in slashcommands
fs.readdirSync('./slashcommands/').forEach(dir => {
fs.readdir(`./slashcommands/${dir}`, (err, files) => {
if (err) throw err;
var jsFiles = files.filter(f => f.split(".").pop() === 'js');
jsFiles.forEach(file => {
var fileGet = require(`./slashcommands/${dir}/${file}`);
try {
client.SlashCmds.set(fileGet.help.name, fileGet);
} catch (err) {
return console.log(err);
};
})
})
})
Hmm, but it just works xd
you want to just load all the files in that dir right?
ok, wait a sec for me to write code
yes thx for your time
let read_rec = dir => {
let files = [];
let x = dir => {
for (let ent of fs.readdirSync(directory)) {
let path = dir + "/" + ent;
if (fs.statSync(path).isDirectory()) x(path);
else files.push(path);
}
};
x(dir);
return files;
}
// fs.readdirSync('./slashcommands/').forEach(dir => {
// fs.readdir(`./slashcommands/${dir}`, (err, files) => {
// if (err) throw err;
// var jsFiles = files.filter(f => f.split(".").pop() === 'js');
// jsFiles.forEach(file => {
// var fileGet = require(`./slashcommands/${dir}/${file}`);
// try {
// client.SlashCmds.set(fileGet.help.name, fileGet);
// } catch (err) {
// return console.log(err);
// };
// })
// })
// })
for(let file of read_rec("./slashcommands/")) {
if(file.split(".").pop() != "js") continue;
var fileGet = require(file);
try {
client.SlashCmds.set(fileGet.help.name, fileGet);
} catch (err) {return console.log(err);};
}
the code is not tested, but you should get the gist
replace directory with dir
sure
It gives this
But I think that the problem is my slash commands
const { SlashCommandBuilder } = require('@discordjs/builders');
const discord = require("discord.js")
module.exports = {
data: new SlashCommandBuilder()
.setName('botinfo')
.setDescription('Geeft info over de bot.'),
async execute(client, interaction) {
var botEmbed = new discord.MessageEmbed()
.setTitle("Botinfo")
.setColor("#0fbfab")
.addFields(
{ name: "Bot naam", value: client.user.username },
{ name: "Gemaakt door", value: "@Daniël#5215" },
{ name: "Bot gemaakt", value: "08-07-2020" }
// { name: "Aantal servers", value: client.guilds.cache.size.toString() },
// { name: "Aantal leden in alle servers bij elkaar", value: },
)
.setThumbnail("https://media.discordapp.net/attachments/738372224968425502/936339295457931274/giveaway_pf_maybe.png")
//.setImage("https://zeroserenity.com/wp-content/uploads/2019/07/Discord-Logo-Red.png")
.setFooter("Bot is gemaakt door @Daniël#5215") //, "https://zeroserenity.com/wp-content/uploads/2019/07/Discord-Logo-Red.png")
.setTimestamp();
return interaction.reply({ embeds: [botEmbed] });
}
}
I Will fix Tomorrow
It gives no error, but when I write / in my server, I don't see any slashcommands
@hard aurora
this is my slashcommand handler that works, but it is without folders, and I want with folders:
const commandSlashFiles = fs.readdirSync("./slashCommands").filter(file => file.endsWith(".js"));
for (const fileSlash of commandSlashFiles) {
const commandSlash = require(`./slashCommands/${fileSlash}`);
client.slashCommands.set(commandSlash.data.name, commandSlash);
slashCommands.push(commandSlash.data.toJSON());
console.log(`De file ${commandSlash.data.name}.js is geladen.`)
}
use my code bro
i literally wrote the code for you
my code do handles folders
what is in the image, is right, what is in the code block, maybe wrong
Yes this is your code...
then what's the deal with the last code block you sent?
What do you mean?
you sent this:
const commandSlashFiles = fs.readdirSync("./slashCommands").filter(file => file.endsWith(".js"));
for (const fileSlash of commandSlashFiles) {
const commandSlash = require(`./slashCommands/${fileSlash}`);
client.slashCommands.set(commandSlash.data.name, commandSlash);
slashCommands.push(commandSlash.data.toJSON());
console.log(`De file ${commandSlash.data.name}.js is geladen.`)
}
Yes because I was trying things because your thing isn't working yet
tell me why my thing is not what you're expecting
it should handle all the files, no matter what folder they are in slashCommands
Me slash commands don't work. When I do / in the server, I see 0 slashcommands, while in my folder slashcommands there are slashcommands that work.
after line 91, add a console.log(fileGet) and post here the output
With this my slash commands work, but then my slash commands are not in separate folders in my slash commands folder
sure!
[nodemon] starting `node index.js`
{
data: SlashCommandBuilder {
options: [],
name: 'help',
description: 'Je krijgt alle informatie in je DM.'
},
execute: [AsyncFunction: execute]
}
{
data: SlashCommandBuilder {
options: [],
name: 'botinfo',
description: 'Geeft info over de bot.'
},
execute: [AsyncFunction: execute]
}
{
data: SlashCommandBuilder {
options: [],
name: 'invite',
description: 'Geeft je handige linkjes.'
},
execute: [AsyncFunction: execute]
}
Started refreshing application (/) commands.
Successfully reloaded application (/) commands.
Corona Depressie is online.
looks like my code works
there's some other piece in your project that is not behaving
I don't understand that it then works with this, but doesn't work with your code. I hope that your code will work 🙂 So say what I have to send
it's not my code that is wrong, but the thing you are doing with it
currently it is not working because you're doing inside the try:
client.SlashCmds.set(fileGet.help.name, fileGet);
(syntax is a bit off cause I didn't have from where to copy-paste)
and in the other one you're doing:
client.slashCommands.set(commandSlash.data.name, commandSlash);
slashCommands.push(commandSlash.data.toJSON());
just copy the last 2 lines, and put them inside my code
commandSlash should be fileGet