NanotechPikachu
NanotechPikachu
DIAdiscord.js - Imagine an app
Created by NanotechPikachu on 2/17/2024 in #djs-questions
Bot not responding to prefix cmds
Hi to all! I have the following in my ./events/messageCreate.js
const { Events } = require('discord.js');
module.exports = {
name: Events.MessageCreate,

execute(message) {
const prefix = "+";
console.log(")")
if (!message.content.startsWith(prefix) || message.author.bot) return;

const args = message.content.slice(prefix.length).trim().split(/ +/);
console.log("/")
const commandName = args.shift().toLowerCase();

const command = message.client.commands.get(commandName) || message.client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
console.log("o")
if (!command) return;

// Check permissions, cooldowns, etc.

try {

command.execute(message, args);

} catch (error) {

console.error(error);

message.reply('There was an error trying to execute that command!');

}
},
};
const { Events } = require('discord.js');
module.exports = {
name: Events.MessageCreate,

execute(message) {
const prefix = "+";
console.log(")")
if (!message.content.startsWith(prefix) || message.author.bot) return;

const args = message.content.slice(prefix.length).trim().split(/ +/);
console.log("/")
const commandName = args.shift().toLowerCase();

const command = message.client.commands.get(commandName) || message.client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
console.log("o")
if (!command) return;

// Check permissions, cooldowns, etc.

try {

command.execute(message, args);

} catch (error) {

console.error(error);

message.reply('There was an error trying to execute that command!');

}
},
};
The bot isn't responding when I do +ping I will attach my ping.js below as msg
6 replies
DIAdiscord.js - Imagine an app
Created by NanotechPikachu on 10/15/2023 in #djs-questions
Loop for bot role has
const rol = "1048495552322609232";
const guild = message.guild;
const mem = [];
const role = guild.roles.cache.get(rol);

if (!role) {
message.channel.send('Cannot find the role!');
} else {
guild.members.fetch()
.then((members) => {
console.log("hu");
members.forEach((member) => {
if (member.bot) {
console.log(`Bot: ${member.user.tag}`);
if (member.roles.cache.has(role.id)) {
mem.push(`<@${member.id}>`);
console.log(`Added: ${member.user.tag}`);
} else {
console.log(`Bot ${member.user.tag} doesn't have the role.`);
}
}
});
message.channel.send('hi');
console.log(mem);
})
.catch((e) => {
console.error(e);
});
}
const rol = "1048495552322609232";
const guild = message.guild;
const mem = [];
const role = guild.roles.cache.get(rol);

if (!role) {
message.channel.send('Cannot find the role!');
} else {
guild.members.fetch()
.then((members) => {
console.log("hu");
members.forEach((member) => {
if (member.bot) {
console.log(`Bot: ${member.user.tag}`);
if (member.roles.cache.has(role.id)) {
mem.push(`<@${member.id}>`);
console.log(`Added: ${member.user.tag}`);
} else {
console.log(`Bot ${member.user.tag} doesn't have the role.`);
}
}
});
message.channel.send('hi');
console.log(mem);
})
.catch((e) => {
console.error(e);
});
}
The problem is that even when bots are in the server having the role, it completely skips the condition and array will be empty
6 replies
DIAdiscord.js - Imagine an app
Created by NanotechPikachu on 10/8/2023 in #djs-questions
Await reaction & loop
Hi. I am trying to use .awaitReactions() to run the addUserToGiveaway on every reaction added to message. But, it only works after the "max" value is reached or timeout happens. I wanna make it such that the code inside it runs on every reaction added. How do I do?
giveawayMessage.awaitReactions({ max: 1000, time: parseDuration(duration) })
.then(collected => {
console.log(Date.now())
const reaction = collected.first();
if (reaction) {
const usersArray = Array.from(reaction.users.cache.values()).filter(user => !user.bot);// Filter out bots and creates array
for (let i = 0; i < winnersCount && i <= usersArray.length; i++) {
addUserToGiveaway(giveawayMessage.id, usersArray[i].id);
}
}
})
.catch(console.error);
giveawayMessage.awaitReactions({ max: 1000, time: parseDuration(duration) })
.then(collected => {
console.log(Date.now())
const reaction = collected.first();
if (reaction) {
const usersArray = Array.from(reaction.users.cache.values()).filter(user => !user.bot);// Filter out bots and creates array
for (let i = 0; i < winnersCount && i <= usersArray.length; i++) {
addUserToGiveaway(giveawayMessage.id, usersArray[i].id);
}
}
})
.catch(console.error);
This is just a part of code. All the things like giveawayMessage and addUserToGiveaway have been declared and no other errors.
4 replies
DIAdiscord.js - Imagine an app
Created by NanotechPikachu on 7/11/2023 in #djs-questions
Banning doesn't delete msgs
I have made a ban code and will attach the important part below. The problem is that when I use the code, it bans the user but isn't deleting messages which I think it should. Plz enlighten me on this issue
await user.ban({ deleteMessageSeconds: 60 * 60 * 24 * 7, reason: reason }
await user.ban({ deleteMessageSeconds: 60 * 60 * 24 * 7, reason: reason }
Thnx
10 replies
DIAdiscord.js - Imagine an app
Created by NanotechPikachu on 3/23/2023 in #djs-questions
Ping command help - Beginner
Hi. I am just a beginner in discord.js. I have done some projects in discord.py. My problem is that, I cannot get heads or tails to make a Ping command in js. I tried the example in guide too as well as in stackoverflow but, couldn't get it I know at least i should give an example, but, i cannot cuz no code is usable for me(as far as i saw). I am thinking of a ping slash command. If u could help me with such a command that has an embed counting the latency and api. It would be helpful for me to understand better. Also, I am using replit to code. Sorry for this foolish question. I can't get any better way other than this
30 replies