and I've just updated to ver 14.6.0 of discord.js and non of my cmds are working why is that my code always worked before hand? example of my code here ->
if (message.content.startsWith('L!poke')) {
let targetMember = message.mentions.members.first();
if (!targetMember) return message.reply('you need to tag a user in order to poke them!!');
// message goes below!
const num = (Math.floor(Math.random()* 6)+1).toString();
message.channel.send({files: [`./poke/poke${num}.gif`]})
//message.channel.send({files:["./nom/"]})
message.channel.send(` ${targetMember.user},your you getting poked!!! -_-`);
//let embed = new Discord.RichEmbed()
//embed.setImage('https://cdn.discordapp.com/attachments/541152846540701706/653867448553963550/fm49srQ.gif')
//message.channel.send(embed);
You need additional intent flag in order to read content of the messages.
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
// This will give you events about messages
GatewayIntentBits.GuildMessages,
// And this is flag you're probably missing:
GatewayIntentBits.MessageContent,
]
});
Also, don't forget that this intent should be enabled on Discord Developers Portal for your bot.
Related
I'm trying to add a role when members join the server, but it says I don't have that permission. How do I add all intents/permissions for the bot?
I'll just leave the beginning of the code.
// Require the necessary discord.js classes
const { Client, Intents, Message } = require('discord.js');
const { Player } = require("discord-player");
const { token, prefix } = require("./config.json");
// Create a new client instance
const client = new Client(
{
restTimeOffset: 0,
shards: "auto",
intents: [
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_BANS,
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
Intents.FLAGS.GUILD_INTEGRATIONS,
Intents.FLAGS.GUILD_INVITES,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MESSAGE_TYPING,
Intents.FLAGS.GUILD_PRESENCES,
Intents.FLAGS.GUILD_SCHEDULED_EVENTS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_WEBHOOKS,
]
});
The error could be coming because of other reasons as well. One explanation behind the error might be that the bot was trying to add a role to a member with a role higher than its own. In that case, you would have to manually rearrange the role hierarchy and put the bot's role on the top.
About the intents: It's not advisable to just add all the intents you want. The whole point of intents was that developers could choose what type of data they wanted their bot to receive. This whole concept is trashed if we just selected all the intents. If you still want to enable all the intents, you can just check for intents calculator in Google, and then copy the intent value given there and paste it like this:
const { Intents, Client } = require("discord.js")
const client = new Client({
intents: new Intents(value) // Insert the value here
})
Okay so, im trying to make an announce command that makes the bot say what the user asks it to write,
the command is working fine but the main problem is that i dont want users that are not moderators/admins to use this command i tried to use if (user.hasPermission("KICK_MEMBERS") but i simply don't know how to implement this into my code, (here it is)
const Discord = require('discord.js');
module.exports = {
name: 'announce',
description: "announce",
execute(message, args){
const developerEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle(`failed to send message`)
.setAuthor('♥Aiko♥', 'https://i.imgur.com/1q9zMpX.png')
.setDescription('please mention the channel first(if this promblem persists contact the developer)')
.setTimestamp()
.setFooter(`©Revenge#7005 | Requested by ${message.author.tag}.`);
if(message.mentions.channels.size === 0) {
message.channel.send(developerEmbed);
}
else {
let targetChannel = message.mentions.channels.first();
const args = message.content.split(" ").slice(2);
let userMessage = args.join(" ");
targetChannel.send(userMessage);
message.delete();
}
}
}
so yeah, any ideas how to make the bot check for the permission and then send the message if the user has it?
i'm pretty new to coding and this bot is my first bigger project so sorry if this question seems stupid
Make sure to use message.member in place of user, and you should implement it at the beginning of your code.
module.exports = {
name: 'announce',
description: "announce",
execute(message, args) {
if (!message.member.hasPermisson('KICK_MEMBERS')) // if member doesn't have permissions
return message.channel.send('Insufficient Permissions');
// rest of your code...
I'm currently making a hug command.
Im trying to make my bot mention the the user that used to command and the one that the user mentioned while using the command, my main problem is the bot sends the '#user has hugged #user' outside of the embed,
here is the code that im using
const messages = ["https://media.tenor.com/images/c6f27ebfd8657a83794329468c27197f/tenor.gif"]
module.exports = {
name: 'embed',
description: "hug embed",
execute(message, args){
const randomMessage = messages[Math.floor(Math.random() * messages.length)]
const hugged = message.mentions.users.first();
const reply = message.reply(`has hugged! <#${hugged.id}>`);
if(!hugged) return message.reply('please mention who you want to hug');
let embeddedHug = new Discord.MessageEmbed()
.setDescription(reply)
.setImage(randomMessage)
message.channel.send(embeddedHug);
}
}
Any suggestions why the bot sends it ouside of the embed?
You are not doing it correctly.
message.reply() is used to send a normal message and automatically mention the author on the beginning of the message.
This is what you want.
const hugged = message.mentions.users.first();
const embedMessage = `<#!${message.author.id}> has hugged <#!${hugged.id}>`;
let embeddedHug = new Discord.MessageEmbed()
.setDescription(embedMessage)
.setImage(randomMessage)
message.channel.send(embeddedHug);
I am trying to send a message through discord.js and I am getting the following error:
(node:10328) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
Here is my code:
// Init
const Discord = require("discord.js");
const bot = new Discord.Client();
const channel = bot.users.cache.get('4257');
// Vars
// Code
bot.on("ready", () => {
console.log("The Bot is ready!");
channel.send("Test");
});
// Login
bot.login(" "); // I will hide this.
What is wrong? Is it the id on the channel variable? I just put in the id of my bot since I didn't know what to put in it.
At first I gave it all the permissions under "Text Permissions", but I also tried giving him admin privs. It still didn't work. What am I doing wrong?
The problem is this line:
const channel = bot.users.cache.get('4257');
Here's what's wrong with it:
const channel = bot.users.cache // this returns a collection of users, you want channels.
.get('4257'); // this is a user discriminator, you want a channel ID
Here's how to fix it:
const id = <ID of channel you want to send the message to>
const channel = bot.channels.cache.get(id)
// ...
channel.send('Test')
Here's an example:
const channel = bot.channels.cache.get('699220239698886679')
channel.send('This is the #general channel in my personal Discord')
How to get a Channel ID
ChannelManager Docs
const channel is empty here. You need to make sure value should be assigned in it.
channel.send("Test");
If its not mendatory that value will come then use try-catch.
try {
channel.send("Test");
} catch(e) {
console.log(e)
}
Please support with vote or answered if it helps, thanks.
I am coding a discord bot using discord.js.
FOR SOME REASON it says Discord not defined error or the bot has no response. Please could you help me? I have never had this error before. Here's the code.
I have include this command in the same main.js file:
if(cmd === `${prefix}help`){
reporthelp = "Report a user. Requires a channel named `reports`to work!";
kickhelp = "Kick a user from the server. Requires a channel named `incidents` to work; you must have the manage messages permission.";
banhelp = "Ban a user from the server. Requires a channel named `incidents` to qork; toy need the BAN MEMBERS permission to use this command!";
warnhelp = "**COMMAND COMING SOON!**";
requiredperms = "**Embed Links, channel named `incidents`; channel named `reports`; channel named `suggestions`; Kick Members, Ban Members, Manage Roles, Manage Members.**"
helpEmbed = new Discord.RichEmbed()
.setDescription(" 💬 **__Help Is Here!__** 💬")
.setColor("#936285")
.addField("**/report #user <reason>**", reporthelp)
.addField("**(COMING SOON)** /warn #user <reason>", warnhelp)
.addField("**/kick #user <reason>**", kickhelp)
.addField("**/ban #user <reason>**", banhelp)
.addField("**/mytag**", "Shows you **your** discoord username#discrim and your user ID. Requires Embed Links permission.")
.addField("**/invite**", "Get a linkto incite meto our server, and an invite link to my suppoer server")
.addField("**/owner**", "see who currently owns the bot")
.addField("**/git**", "**SOURCE CODE AVAILIBLE SOON**")
.addField("**/token**", "View the bot's super secret bot token!")
.addField("**/serverinfo**", "displays some basic server information!")
.addField("**/botinfo**", "displays basic bot information!")
.addField("**/ping**", "Get the bot to respond with `pong` ")
.addField("**/hosting**", "Bot finds a good website for bot/web hosting")
.addField("**/quotes**", "bot responds with some lovely quotes!")
.addField("**__Required Permissions__**", requiredperms)
// .addField("**COMING SOON!**/suggest <suggestion>", "suggest something. Requires channel named `suggestions`")
.setTimestamp()
.setFooter("Use /invite to invite me to your server!")
return message.channel.send({embed: helpEmbed});
}
This is how I've defined everything:
const botconfig = require("./botconfig.json");
const tokenfile = require("./token.json");
const Discord = require("discord.js");
const bot = new Discord.Client({disableEveryone: true});
bot.on("ready", async () => {
console.log(`${bot.user.username} is active in ${bot.guilds.size} servers!`);
bot.user.setActivity("rewriteing main.js...", {type: "WATCHING"});
//bot.user.setGame("Lookin' out for ya!");
});
bot.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
const prefix = botconfig.prefix;
const messageArray = message.content.split(" ");
const cmd = messageArray[0];
const args = messageArray.slice(1);
const bicon = bot.user.displayAvatarURL;
I either get no response/error, or I get the error discord is not defined.
I'm also very new here, sorry If I didn't ask a question clearly...
The code is correct, but I had redfined discord in a different part of the file....
my advice would be to alays read the code over again!