Having Issues with "Client" inside MessageEmbed - discord.js

Code:
const specifyembed = new Discord.MessageEmbed()
.setAuthor("Auto-Partner", client.user.displayAvatarURL())
.setThumbnail(client.user.displayAvatarURL())
.setDescription("**__Want to grow fast?__** \nWith this bot you can gain up to **3,000 Members** per week! \nThis bot will share your server in many active servers and to many active users! \nSimply add me to your server and use the command ``-partner {MESSAGE}``")
.addFields([
{
name: '**__Bot Invite Link:__**',
value: '[- Click To Add Bot -](your link goes here)'
}
])
.setTimestamp()
.setFooter("© Auto-Partner")
if(!args[0]) return message.channel.send(specifyembed)
Error:
(node:7920) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'client' of undefined
So if anyone got any solutions on how to fix this please help me out.

Issue was in util.js and command handler, i havent connected util.js with command handler, depends on what your issue is hopefully this one helps, i know it can depend.

Related

How to get bot to reply to user with a (#)ping

I am trying to get a bot to respond to people with a ping in the message, for example: "#user", but everything I've tried have given me not a function error or undefined error. All the stuff I can find about it is either outdated for discord.js v14 or it is for discord.py
Here is my code:
client.on("messageCreate", (message) => {
if (message.content.startsWith("test")) {
const user = message.author.userId();
message.channel.reply(`Hello <#${user}>`)
}
});
I've also attempted variations of the .userId() part - such as .tag, .user.id, and .username but all of them have come back with some sort of undefined error. I know it says userId is a snowflake on discord.js but I am unsure on how to use that for I am fairly new to javascript and discord.js. Also, please know that I am using Replit to host the bot and have discord.js#14.5.0 installed.
So, there are a couple issues here.
Issue 1
message.author.userId() is not a function. When trying to get a user's ID, you want to know what each property is returning.
message -> returns the Message object, which contains the data for the message.
message.author -> returns the User object, which contains the data for the user profile.
message.member -> returns the Member object, which contains the data for the guild member profile.
And so on.
In this case, you're going to want to get the User object: being message.author. You've already figured this out.
Now, the User Object has it's own set of properties (which you can find in the documentation at https://discord.js.org/).
The property that you are looking for is: .id, or in your use-case, message.author.id.
Your other attempts, message.author.tag returns the tag, message.author.user.id will throw an error, and message.author.username returns the user's username.
Issue 2
Your second issue is the .reply() method that you're using. The Channel Object doesn't have a .reply() method, but the message does.
So, how you would write this code:
client.on("messageCreate", async(message) => {
if(message.content.toLowerCase().startsWith("test")) {
// Note that I added the .toLowerCase() method to ensure you can do tEST and it still works!
message.reply({ content: `Hello, ${message.author}!` });
}
});
Also, a cool feature that discord.js has is that you can supply the User or Member Object to the content of a message, and it will automatically mention the desired person.
Hope this helps!

I have a problem with discord.js v12 when trying to run the bot

im running a discord.js v12 bot and when i try to run it
this error pops up
client.user.setActivity(newActivity);
^
TypeError: Cannot read properties of null (reading 'setActivity')
at Timeout._onTimeout (C:\Users\Alexu\Desktop\cookie checker\events\ready.js:19:19)
at listOnTimeout (node:internal/timers:568:17)
at processTimers (node:internal/timers:510:7)
This means the client is not ready at the time. Put this in the ready event
client.once("ready", () => {
client.user.setActivity(newActivity)
}
The code seems correct. That the value is null maybe means that no user was found. Maybe something goes wrong with login. If the rest of the functions also don't work, then I would advise checking if the credentials are correct.

Guild delete event returns undefined

So my discord bot smartwiki was recently verified and I have this event where it just sends undefined idk why.. advaith told it comes cause one of the bot server is on an outage but I tried removing bot from some guilds and those guilds weren't on an outage but I get undefined (I have presence intent btw) also thsi isn't cause of intents cuz my guild create works fine this did too but it got undefined after my bot went verified
Code:
client.on('guildDelete', guild =>{
client.user.setActivity(`Serving ${client.guilds.cache.size} Servers with a total of ${client.users.cache.size} users and ${client.channels.cache.size} Channels!`);
const Logs = '809839910675546122'
client.channels.cache.get(Logs).send(
new Discord.MessageEmbed()
.setTitle("I Was Removed From a Guild :c")
.addField("Guild Name" , `${guild.name}`)
.addField("Guild Members" , `${guild.members.cache.size}`)
.addField("Guild Id" , `${guild.id}`)
.addField("Guild Owner" , `<#${guild.ownerID}> | Id: ${guild.ownerID}`)
.setFooter(`SmartWiki is Currently in ${client.guilds.cache.size}guilds!`)
.setTimestamp()
.setThumbnail("https://cdn.discordapp.com/attachments/776925179947384884/808370331856535582/standard_1.gif")
.setColor('RED')
)
})
Image: https://imgur.com/a/IjdioBC
Getting the same thing recently with my bot. Don't know why. Seems to appear before the bot logs in and also after, has been for a few days now. Only on bootup though. Odd...

TypeError: channel.send is not a function (Deprecated?)

Im trying to build a discord bot but I need to send a message to a specific channel. I've given it 100 tries but keep getting:
TypeError: bot.channels.fetch(...).send is not a function.
Everywhere I read, I see "use channel.send()" but I cannot find an actual fix for my problem. Is channel.send() deprecated? Heres the line that the error throws an error on:
bot.channels.fetch(id).send(message);
I know channels.get() was depricated and when using .fetch(id), I get the channel object however it wont let me send the message. ANY help will be appreciated as I have spent days on this alone.
Thanks.
Full block of code:
var reportEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('New Report')
.setAuthor(msg.author.tag)
.setDescription(reportMessage)
.setTimestamp();
console.log(bot.channels.fetch('my channel id'));
bot.channels.fetch('my channel id').then(channel => {
channel.send(reportEmbed);
});
When console logged, I get the correct channel object.
Try using:
bot.channels.cache.get(id).send(message)
Instead
As I can see in the documentation, the fetch() method returns a promise. (Link)
So, in order to get the channel, you need to use the current code:
bot.channels.fetch("id").then(channel => {
channel.send(message);
});

Discord,js bot making a channel

I am trying to make my discord bot create a channel! I have tried many way's but none of them work! Note: this is discord.js! Here is the code I have come up with! IT DOES NOT WORK!
guild.channels.create('new-general', { reason: 'Needed a cool new channel' })
'guild' must be defined in some way. You can get it from a message for example by using message.guild or even by its name using client.guilds.find(guild => guild.name === "Guild Name");

Resources