So I want to make an invite to default channel of the server command was executed in.
const embed = new Discord.MessageEmbed()
.setAuthor("Testt", client.user.displayAvatarURL())
.setTitle("title")
.setThumbnail(client.user.displayAvatarURL())
.setDescription("description")
.setTimestamp()
.setFooter("© Test", client.user.displayAvatarURL())
channel.send(embed)
So I want invite to be above MessageEmbed
Since defaultChannel is not a thing anymore I made it like this:
let invite = await message.channel.createInvite({
maxAge: 0, // 0 = infinite expiration
maxUses: 0 // 0 = infinite uses
})
message.channel.send(`${invite}`, "test")
Related
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.
I am working on a discord bot and want to make it able to ban and kick the users which I mention, the issue is that even if it does say that the user I mentioned was banned successfully, it really wasn't. How can I fix this?
kick.js
name: 'kick',
description: "`Executing this command will kick the given user.`",
execute(message, args){
const target = message.mentions.users.first();
if(target){
const memberTarget = message.guild.members.cache.get(target.id);
memberTarget.kick();
message.channel.send("**The given user has been kicked.**");
}else{
message.channel.send("`You have to specify who you want to kick!`");
}
}
}
ban.js
name: 'ban',
description: "`Executing this command will ban the given user.`",
execute(message, args){
const target = message.mentions.users.first();
if(target){
const memberTarget = message.guild.members.cache.get(target.id);
memberTarget.ban();
message.channel.send("**The given user has been banned.**");
}else{
message.channel.send("`You have to specify who you want to banned!`");
}
}
}
You can put the messages just before the kick/ban, so that the user is available for the client:
const memberTarget = message.guild.members.cache.get(target.id);
memberTarget.kick();
message.channel.send("**The given user has been kicked.**");
becomes
const memberTarget = message.guild.members.cache.get(target.id);
message.channel.send("** <#"+ target.id + "> has been kicked.**");
memberTarget.kick();
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 have a bot that sends partner to my server's partner channel. The invites that the bot creates must be permanent and infinite uses. How can i do that?
My code to create an invite:
let invite = await message.channel.createInvite({
maxAge: 86400000, //1 day
maxUses: 1
}).catch(console.error);
Just use the max values provided in the discord.js docs:
let invite = await message.channel.createInvite({
maxAge: 0, // 0 = infinite expiration
maxUses: 0 // 0 = infinite uses
}).catch(console.error);
Discord createInvite() Docs