I'm working on a discord bot, when a user joins/leaves the server there's a message for that, but I'm getting a warning in my terminal that says
DeprecationWarning: Passing strings for MessageEmbed#setAuthor is deprecated
Here is some of the code in case you need it.
const Welcome = new MessageEmbed()
.setColor("RED")
.setAuthor(user.tag, user.avatarURL({dynamic: true, size: 512}))
.setThumbnail(user.avatarURL({dynamic: true, size: 512}))
.setDescription(`
Welcome ${member} to **${guild.name}!**`)
.setFooter({
text: `${user.id}`
})
It's just a deprecation warning. You can safely ignore it.
It means that in a future version of the Discord client, you won't be able to use the function setAuthor.
There's usually a replacement function or alternate method for it in newer versions but if you don't plan on upgrading then you can ignore it.
You should, however, always upgrade your dependencies as they can contain bug fixes and security updates.
In your case, Discord specifies that setAuthor accepts an object in newer versions (although you can still use a string in your version).
Check the Discord JS Docs for more information.
.setAuthor({name:`${user.tag}`,
iconURL: `${user.avatarURL({dynamic: true, size: 512})}`})
you can use this for the new version
Related
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]
});
I keep getting this error
C:\WINDOWS\Temp\OneDrive\Documents\microsoft\node_modules\discord.js\src\client\Client.js:544
throw new TypeError('CLIENT_MISSING_INTENTS');
^
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client
but when I do add it it says client is declared
const Discord = require('discord.js')
const client = new Discord.Client();
client.on('ready', () => {
console.log("Bot is online!")
});
const allIntents = new Intents(32767);
how do I fix this?
Since discord.js v13, you're required to explicitly pass intents when instantiating a new Client.
Intents are what tells Discord about which events your bot wants to receive, so it doesn't send too much unnecessary stuff that you're not going to use in your code.
To do this, you don't even have to do the numbers thing. The library supports passing intents as an array of strings (and then it does the math behind the scenes).
Here's an example if you wanted to receive some information about the guilds your bot is in:
const client = new Discord.Client({
intents: [
'GUILDS',
'GUILD_MEMBERS'
]
});
You can add as many intents as you want, and a complete list of the currently supported ones can be found in this discord.js documentation page. There's also this official documentation page by Discord that tells you which intent controls which events.
When I had discord.js v12 everything was fine with statuses, but now with discord.js v13 I got the following problem:
message.guild.members.cache.filter(member => member.presence.status === "(status)").size;
In this code, it throws an error:
cannot read property 'status' of undefined
I also checked message.author.presence.status, the result is the same.
I also tried something else and it surprised me a little: message.guild.members.cache.get(bot.user.id).presence.status and message.guild.members.cache.get(message.author.id).presence.status both work.
By using optional chaining (?.), you are able to 'bypass' the error cannot read property 'status' of undefined (Node.js v14 and higher only).
const presence = message.guild.members.cache.filter(member => member.presence?.status === "online");
console.log(presence.size);
Note that you will not be able to track the presence from offline users, presence data will return undefined instead.
If you receive errors like Error [DISALLOWED_INTENTS]: Privileged intent provided is not enabled or whitelisted., you simply have to follow these steps:
Discord requires bot developers to enable PRESENCE INTENT to track presence data from server members. So the first step is to enable this. This can be done in the Developer console:
https://discord.com/developers/applications/id_of_your_bot/bot
The next thing is to make sure you have enabled the GUILD_PRESENCES flag as well, as this is required to track the presence data from server members. So for example:
const { Client, Intents } = require("discord.js");
const bot = new Client({
intents: [
// Your other intent flags
Intents.FLAGS.GUILD_PRESENCES // This line is required to track presence data
]
});
I am having issues across all the commands that share the same system as this one below.
All commands like ban, mute, kick are identical to this one and act the same in the mongoose part.
Take a look below, in the given code block.
const warnDoc = new WarningModel({
guildID: message.guild.id,
memberID: member.id,
warnings: [reason],
moderator: [message.member.id],
date: [Date.now()],
})
warnDoc.warnings.push(reason)
warnDoc.moderator.push(message.member.id)
warnDoc.date.push(Date.now())
await warnDoc.save().catch(err => console.log(err))
message.delete(message.author);
const logs = message.guild.channels.cache.find(channel => channel.name === "albot-mod-system");
if (!logs)
return console.log(`No logs channel exists in ${message.guild.name}`)
let warnembed = new Discord.MessageEmbed()
.setTitle(`Moderation | Audit Log`)
.addField("**Member**", `${member}`)
.addField("**Action**", "Warn")
.addField("**Reason**", `${reason ? `${reason}` : ''}`)
.addField("**Warning Count**:", `${warnDoc.warnings.length}`)
.setTimestamp(message.createdAt)
.setFooter(message.member.displayName, message.author.displayAvatarURL({ dynamic: true }))
.setColor(`#000000`)
logs.send(warnembed);
member.send(`You were warned in **${message.guild.name}** for: **${reason}**.`);
let warnEmbed2 = new MessageEmbed()
.setAuthor(`Moderation`)
.setDescription(`${member} has been warned successfully with the reason: ${reason}`)
.setTimestamp(message.createdAt)
.setFooter(message.member.displayName, message.author.displayAvatarURL({ dynamic: true }))
.setColor(`#000000`)
message.channel.send(warnEmbed2);
}
}
This is my warn command and when i run it, it normally gives 1 warning, but instead registers two. This issue came out of nowhere and it is confusing.
Anyone know the root issue of this?
Stuff ive tried:
Try a older mongoose version, no luck.
Play around with the mongoose parts in the code, no luck.
Revert to older versions of the command, no luck.
I honestly do not know what is causing this.
You're initializing WarningModel with a warnings array (warnings: [reason]) and pushing to it again with the same reason. Remove the push call.
Remove
warnDoc.warnings.push(reason)
You should also remove the following lines since moderator and date values are set while initializing the document.
warnDoc.moderator.push(message.member.id)
warnDoc.date.push(Date.now())
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