I trying to make a discord bot using javascript..but it giving me error - javascript

enter image description here
it giving me this error:
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
^
TypeError: Cannot read properties of undefined (reading 'FLAGS')
I expect it to run my bot on my discord channel

It says that the object Intents are undefined and doesn't have property FLAGS. Please double-check your object, print it with console.log see if it actually there.

Related

How to use "client" in my commands? (Discord.js v13)

TypeError: Cannot read properties of null (reading 'tag')
This error comes whenever I try to use client in a command like this: client.user.tag
my message.js includes:
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS]});
and
command.execute(client, message, args, MessageEmbed);
and my command file also contains: execute(client, message, args, MessageEmbed)
then also i am getting this error: TypeError: Cannot read properties of null (reading 'tag') a help will be really appreciated...
UPDATE:
Ok i just console logged the client and got this:
user: null,
application: null,
now why is the client user = null?
This looks like a caching issue make sure that you have not disabled user caching since this will include the client user.
client is a variable that holds the Discord bot client. You should read the docs to learn more about how it can be used.
It seems you are trying to get the client tag. If you read the docs, you will see that the client object has a property called user, which holds the user object. Since user objects hold the tag property, you're done.
client.user.tag

TypeError: Cannot read properties of undefined (reading 'send')

I am writing a discord bot with node.js. I want the bot to send a message automatically when a member joins or leaves the channel. But I keep getting an error about the send function. Can you help me?
[1]: https://i.stack.imgur.com/4URud.png
module.exports = (client) => {
client.on('guildMemberRemove', (member) => {
console.log(member);
member.guild.channels.cache.get("1234567890912345678").send("byeee");
});
}
member.guild.channels.cache.get("1234567890912345678") is undefined, so there is no send() function. You need to identify why that channel is undefined or doesn't exist or find that channel using another method.

Trying to call send function in web3 and it returns an error => Uncaught (in promise) Error: Returned error: unknown account

I am trying to call a method of smart contract which is a write method
const temp = await goin_contract.methods
.increaseAllowance("0xEd61D93121D0b8435f9D2AaCB7dea0A3D067c4E2", stakeValue)
.send({ from: account });
However whenever I call this method it returns this error
*Uncaught (in promise) Error: Returned error: unknown account
at Object.ErrorResponse (errors.js:28:1)
at index.js:302:1
at XMLHttpRequest.request.onreadystatechange*
Read methods of smart-contract are working perfectly.
I have read some articles on how to solve this error but cant find a definite solution. Any help will be appreciated.
You have to use Metamask provider instead of node URL const web3 = new Web3(window.ethereum);

Discord bot won't log messages

Currently new to coding Discord bots, and was following along with an online tutorial.
I'm stuck on trying to get the client's message method to log the message that the user typed.
Here's my code:
require('dotenv').config();
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILD_MESSAGES"] });
client.on('ready', () => {
console.log(`${client.user.tag} has logged in`);
});
client.on('message', (msg) => {
console.log(msg.content);
});
client.login(process.env.TOKEN);
The tutorial is a bit outdated since Discordjs has been updated, and I'm not sure if the problem has to do with the intent or something else.
The bot is able to login to the server and shows up as online, with the console registering the login.
However, the console is never able to log any messages sent. Any help would be appreciated.
You need to include both intents:
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
You can still use client.on('message') but it will come with a DEPRACATED warning, so as of v13 you should use client.on('messageCreate')
As per the docs:
//discord.js V12
-client.on('message', (msg) => {
//discord.js V13
+client.on('messageCreate', (msg) => {

Type Error: Cannot read the property of "user" of null

I am making a server info command in discord.js but got the error
Cannot read property of "user" of null
It works before, but now it does not. I have no idea why
Here is the code that has the problem:
.addField("Owner", `${message.guild.owner.user.username}#${message.guild.owner.user.discriminator}`, true)

Categories