Discord Unban All User command ( js ) - discord

Just a simple unban all users in guild command for my next ban royale in Discord. Any help would be greatly appreciated!

I wrote this based on the fact that you were writing your bot in discord.js as you did not give much information when writing and all i could see was the tags.
Try this-
const member = message.member;
switch(message.content.toLowerCase()){
case (!"unban all"):
if(member.hasPermission('ADMINISTRATOR')){
message.guild.fetchBans().forEach((fB)=>{
message.guild.members.unban(fB.user.id);
})
// All Users get unbanned
} else {
// User does not have permission.
}
}
})
If this does not work please let me know.
P.S. I'm kinda new to coding so if it is wrong please don't be angry with me.

Related

How to make my discord.js chat bot reply to a word in a sentence

I’m trying to set up a chat reply bot for helping admin a game discord server. I have a list of words for it to reply to and can get him reply to them no problem. The problem I’m having is that one of the words is ESP so when someone was to type the word response it picks up the word esp in the word response and replies when I don’t want him to. Another example is the work hack. When someone types hacksaw ridge in chat he replies to that to. I want it to just look for the word esp along with a few other cheating terms and not look for it in the middle of a longer word.
let cheater = ["cheating", "cheater", "aim_bot", 'esp', "hack"]
client.on('messageCreate', (message) => {
if (message.author.bot) return false;
if (cheater.some(w => message.content.toLowerCase().includes(w))) {
message.reply('if you think someone is cheating report it here <#976517390701563955>');
}
})
Any help would be greatly appreciated
Thanks.
One of ways to solve it is very simple in fact, if you want your bot to react only to full words, you can use:
if(message.content.toLowerCase().includes(` ${your_variable} `)) {
// your code
}
instead of what you have in your code
You need to look for an Array.prototype.some() to get the message in your array. To accomplish this.
client.on('messageCreate', async(message) => {
if (message.author.bot) return false;
let messages = ["cheating", "cheater", "aim_bot", 'esp', "hack"]
if(messages.some(element => message.content.toLowerCase().includes(element))) {
message.reply("if you think someone is cheating report it here <#976517390701563955>")
}
})

discord.js make a bot delete a given number of messages

I've started creating a discord bot and I've wanted it to start moderating my server. my first command to try was 'mass delete' or 'purge' which deletes the number of messages a user gives.
But I'm pretty new to java and discord.js so I have no idea how to start.
// code here to check if an mod or above
// code to delete a number of message a user gave
}```
For permissions checking, you could simply check for the message author's roles using:
if (!message.member.roles.cache.has(moderator role object)) return;
Overall, you should be looking at the bulkDelete() function that can be found here.
Although, since you don't really know how to really develop bots yet from what you're saying, I won't be telling you the answer to your problem straight ahead. I'd highly recommend learning some JavaScript basics (Also, keep in mind Java != JavaScript) as well as Discord.js basics before you jump head straight into what you want to create.
I'd highly recommend WornOffKeys on YouTube, they're fantastic.
Check user permission first using
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You have no permission to access this command")
check bot permission using
if (!message.guild.me.permissions.has("MANAGE_MESSAGES")) return message.channel.send("This bot have no permission to delete msg!")
return a message when user havnt mention a select message
if (!args[0]) return message.channel.send("no messages have been selected")
then as Bqre said using bulkdelete()
try {
await message.channel.bulkDelete(args[0])
} catch (e) {
console.log(e); //err
}
hope you find it useful!

Making a welcome message in discord.js

I'm a starting developer in discord.js, and recently attempted at making welcome messages.
Could you help me, please?
client.on('guildMemberAdd', (member) => {
console.log(member)
const message = `Hello <#${member.id}>`
const welcomeChannel = member.guild.channels.cache.get('775672625018961940')
welcomeChannel.send(message)
})
I'm just sharing the same answer from Worthy Alpaca.
This is so that people who are googling can see the answer.
This may answer your question: Discord.js Bot Welcomes Member, Assign a Role and send them a DM
Good luck with the rest of your bot and have a nice day!
You must enable intents. See more here: https://support-dev.discord.com/hc/en-us/articles/360056426994

Is it possible to create a guild invite link once a bot joins said guild?

Alright, so basically I just want to know if it's possible to do what I said in the title. If so, could somebody tell me? It'd be much appreciated. Thanks!
Discord.js docs can be found here.
client.on('guildCreate', guild => {
if (!guild.me.hasPermission('CREATE_INSTANT_INVITE')) return console.log('Insufficient permission.');
guild.channels.first().createInvite()
.then(invite => console.log(invite.url))
.catch(err => console.error());
});

Working on discord.js, and my bot keeps spamming the same message

I've been working on a bot in discord.js and have made a basic bot. Whenever I try to use the 'dadjoke' or 'dadpun' command, it just sends the placeholder messages over and over again. Any help?
The code is here:
} else if (message.content.startsWith(`${prefix}joke`)) {
var repl = rand[Math.floor(Math.random()*rand.length)];
message.channel.send(repl);
} else if (message.content.startsWith(`${prefix}pun`)) {
var repl2 = pun[Math.floor(Math.random()*pun.length)];
message.channel.send(repl2);
Thanks in advance!
Try adding this to the top of your client.on("message", ...) code.
if (message.author.bot) return;
This might solve your problem.

Resources