Discord bot not loading - discord.js

My discord bot works properly but today something sus is happening. when i run the bot the thing is just loading and it just says
The terminal
It doesnt run the bot. Its supposed to log "Beta Pog" but its not has this happened to you?
I am using a event handler and its a simple console.log()
but its not working, I tried to restart it but it still doesnt work.
Code for the ready event
module.exports = {
name: 'ready',
once: true,
execute(bot) {
console.log(`Beta Pog`)
bot.user.setActivity('with beta testing')
},
};

I would steer clear of command handlers until you have a solid knowledge of javascript and discord.js in general.
We cannot debug your problem because we do not have the bot command handler code.
Here is how you would do this, using 1 index.js file and simply log "beta pog"
// require packages
const Discord = require("discord.js");
// initialise the bot
const bot = new Discord.Client();
bot.on("ready", () => {
console.log(`Beta Pog`);
bot.user.setActivity('with beta testing');
});
I would recommend using ; semi colons, it saves debugging nasty errors later
Also, I am unfamiliar with node ., try the long version node index.js etc. If the issue persists, try deleting the node modules folder, and doing npm install to recreate the packages in case it is caused by a corrupt package.
Here is a simple command handler, with a guide to follow

Related

Discord.js - Delete all channel by running Discord-Bot without a command

Hey i need for a project a tool to delete all channsl on a Discordserver via a Discord.js Bot.
i got one with handlers and this is my "event code" but dosent work.
Discord.js v14
const client = require("../../index");
module.exports = {
name: "blacksheep"
};
client.on("ready", () => {
var server = Client.guilds.get('1045245227264397382');
for (var i = 0; i < server.channels.array().length; i++) {
server.channels.array()[i].delete();
}})
i dont find the right way to get it worked. thx <3
Then i start the bot all Channels should be deletet without any command.
You need to include error messages or what the results of running this code was for us to actually help you, but for now I'm going to assume that everything in your bot and bot event handlers is working except for the last three lines that loop through the channels and delete them. If that's the case, then you just need to change those lines to something like this (replace your for-loop block with this):
server.channels.cache.forEach((channel) => {
channel.delete();
});
This accesses the server's channel cache, which is a collection, and so it uses the collection's forEach function to loop through all the channels, and then calls each of the channels' delete() functions to delete them.
Note that you may experience severe ratelimiting when doing this, because Discord has heavy ratelimits on requests to server channels.

Add / Remove reaction event no longer firing Discord.js v13

Good morning everyone,
I am currently running into one pretty irritating issue with getting a users messages from before the bots launch. I have been able to do this in the past (a few months ago), but it seems they have replaced the Intents.FLAGS approach for GatewayIntentBits. This has not been to complicated to change, but some problems have occurred.
One of the biggest issues, and the reason for this question is that even though I contain data in my intents that would allow for reading of reactions, as well as adding partials (I read it may help online). This does not seem to fix the issue.
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers], partials:["Message", "Channel", "Reaction"]})
. . .
client.on('messageReactionAdd', _ => {
console.log('a reaction has been added');
});
client.on('messageReactionRemove', _ => {
console.log('a reaction has been removed');
});
I know this isn't allot to go off of, but I have tested it with barely anything in my application and I still run into this error. Is this a known issue with the change to GatewayIntentBits? I would love to continue working on this bot.
Thank you for any assistance you may be able to provide.
EDIT: I have managed to get the reactions to work on the application now. I have not even started touching those old messages, and its working. Thank you for your help. My best bet of why its working is that the messages needed to be resent with the partials and intents specified above. I dont know why this didnt work before, but whatever.
Your gateway intent bits are fine, you need to do something similar to that for the partials as well, you need to import partials from discord.js and use them like that.
const { Client, Partials } = from 'discord.js';
const client = new Client({
intents: [],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
});

How can I change the volume of my discord bot in discord.js V13?

I am creating a Discord Bot and I am getting along quite good, however, I am now trying to implement a command for changing the volume of the bot and I can't figure out how to do it. All I am finding on the Internet is for V12 or below, but I am using the new version of discord.js - V13. Here is what I have for playing the music:
const connection = await connect(channel);
const audioPlayer = createAudioPlayer();
const stream = createStream(song.url);
const resource = createAudioResource(stream, {
inputType: StreamType.Arbitrary,
});
stream.on('error', () => playQueue(guild, channel));
connection.subscribe(audioPlayer);
audioPlayer.play(resource);
This all works but does one of you know how to change the volume?
Side question:
I am also trying to make a /seek <time> to jump to any place in the video and neither am I making any progress with that.
I fixed it now, thanks to Leau:
The problem I had was that I was trying to set resource.volume to the value, whereas I actually would have had to do it via resource.volume.setVolume() with the #discordjs/opus package installed and the option on resource for inlineVolume set to true

discord.js say command help meeee

so im trying to put this in a .js file in my replit discord bot and it wont power up, any know how to fix it? this Is how i did my other things but it includes the prefix, and i don't want the prefix to show it, like, when someone says hi i want the bot to say for example hello back to him. enter image description here
client.on("message", async message =>{
if (message.content.startsWith("ce faci"))
{
message.channel.send(uite ma scarpinam la coaie)
}
If you haven't already, go to the Discord Developer Portal (https://discord.com/developers/applications), click "New Application", give it any name you want, go to the left side of the screen and click on "Bot", and press the button "Add Bot", and press "Yes, do it!" to the pop-up. There should be a token that's been generated. Copy it and put it in the code template bellow.
// Import discord.js and create the client
const Discord = require('discord.js')
const client = new Discord.Client();
// Register an event so that when the bot is ready, it will log a messsage to the terminal
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
})
// Register an event to handle incoming messages
client.on('message', async msg => {
// Check if the message starts with '!hello' and respond with 'world!' if it does.
if(msg.content.startsWith("!hello")) {
msg.reply("world!")
}
})
// client.login logs the bot in and sets it up for use. You'll enter your token here.
client.login('your_token_here');
It might be helpful to use a guide, and you'll find plenty of them on YouTube that teaches you the basics of using Discord.js.
If this is your first time coding in JavaScript or coding in general, I'd suggest that you go on websites such as Codecademy, freeCodeCamp, Khan Academy, YouTube, W3Schools, etc. to learn the basics.

React and Nodemailer

I am running VSCode, Nodejs, Nodemailer, and Reactjs in a Windows machine, but I cannot get Nodemailer to send email. According to the instructions in the web, it should work. Finally I did the following: I created two empty folders in both of which I ran node init, installed Nodemailer, and copied the email sending code. In the other folder I also ran create-react-app. Then I edited the files just enough to get the sending code running.
In the first folder it works without problems, but in the folder with React, it does not do anything. Not even the usual following if(error)/else(success) statements get executed, they are just jumped over. However, the code before and after the transporter.sendMail (or .verify) part are executed... Anyone know why this happens or how to fix it?
This is the code I run in both cra and the non-cra folders:
const nodemailer = require("nodemailer");
const SendEmail = message => {
const transporter = nodemailer.createTransport({
service: "Gmail",
auth: {
user: "from#gmail.com",
pass: "xxxxxxxx"
}
});
transporter.verify(function(error) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});
const mailOptions = {
from: "from#gmail.com",
to: "to#gmail.com",
subject: "Subject",
text: message,
html: "<b>Html</b>"
};
transporter.sendMail(mailOptions, (err, info) => {
if (err) console.log(err);
else console.log(info.response);
});
};
module.exports = SendEmail;
Tim
Gmail has spam filter to prevent spam, so most probably, you may get it pass through sometime and not most time without proper configuration.
and it is not a good idea to send your email in your client app, such as react. Since everyone can access to your email and password to do nasty thing, which is not really a good idea.
Best practice is to request your node server to send mail.
Other than, I noticed that you used gmail to do that. There are some free mail fake stmp server that you can do spamming without the mail provider to flag you as spam user. Such as mailTrap, if you are just interested to test, is react able to send email, try it with mailtrap. I never do it, but still it is better than using your own email provider, as they might have filter rules about it, could be the reason, you are not able to send it.

Resources