I am trying to create Welcome bot for discord.
And I ran into problem.
I must say that this bot development is new to me and I am just trying to create something for my friend's Discord server.
Now, bot starts and it's running, but it's supposed to send that "Welcome message" and other stuffs in channel I provided, but it doesn't do anything.
Here's the part of code I wrote and I think bug occurs there.
client.on('guildMemberAdd', member => {
let channel = member.guild.channels.find("name","💬✦general");
let memberavatar = member.user.avatarURL
if (!channel) return;
let embed = new Discord.RichEmbed()
.setColor('RANDOM')
.setThumbnail(memberavatar)
.addField(':bust_in_silhouette: | Ime : ', `${member}`)
.addField(':microphone2: | Zdravo!', `Dobro došao u dolinu , ${member}`)
.addField(':id: | User :', "**[" + `${member.id}` + "]**")
.addField("**[" + `${member.id}` + "]**",'Pročitaj naša pravila u',"**[#📖✦pravila]**")
.addField(':family_mwgb: | Sada si član', `${member.guild.memberCount}`)
.addField("Name", `<#` + `${member.id}` + `>`, true)
.addField(':family_mwgb: | Luda zabava tek počinje')
.addField('Server', `${member.guild.name}`, true )
.setFooter(`**${member.guild.name}**`)
.setTimestamp()
channel.sendEmbed(embed);
});
let channel = member.guild.channels.find("name","💬✦general");
I think that this could be problem, but I am not entierely sure.
Debugger doesn't show anything except: Logovan si kao Crack House Welcome#6046!
Which I wrote to make sure bot is running, it means "You are logged as".
Thank you in advance
client.on('guildMemberAdd', member => {
let channel = member.guild.channels.cache.find(ch => ch.name === '💬✦general');
let memberavatar = member.user.displayAvatarURL({ dynamic: true });
if (!channel) return;
let embed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setThumbnail(memberavatar)
.addField(':bust_in_silhouette: | Ime : ', `${member.user}`)
.addField(':microphone2: | Zdravo!', `Dobro došao u dolinu , ${member.user}`)
.addField(':id: | User :', "**[" + `${member.id}` + "]**")
.addField("**[" + `${member.id}` + "]**",'Pročitaj naša pravila u',"**[#📖✦pravila]**")
.addField(':family_mwgb: | Sada si član', `${member.guild.memberCount}`)
.addField("Name", `<#` + `${member.id}` + `>`, true)
.addField(':family_mwgb: | Luda zabava tek počinje')
.addField('Server', `${member.guild.name}`)
.setFooter(`${member.guild.name}`)
.setTimestamp()
channel.sendEmbed(embed);
});
Also make sure that you use the latest version of discord.js by using
npm i discord.js#latest
or
yarn add discord.js#latest
in your terminal. Then define Discord by writing
const Discord = require('discord.js');
in the first line.
Related
I am attempting to create a kick command for a bot and its working fine however when the bot logs the embed it doesn't display the data in the variable but [object Object]
The Embed Output
My code is as following
exports.run = async (client, message, args) => {
const username = message.mentions.members.first().user.username; //gets the first mentioned users username
let member = message.mentions.members.first();
if(!member) return message.reply("Please mention a valid member of this server");
if(!member.kickable) return message.reply("I cannot kick this member!");
const reason = args.slice(1).join(' ');
const kickedmessage = new MessageEmbed() //embed to send to a logs channel
.setColor('#1773BA')
.setTitle('User Kicked')
.setDescription({username} + "had been kicked for " + {reason})
;
client.channels.cache.get("771835493305286688").send(kickedmessage)//output the embed
member.kick(reason);
I am using discord.js v12
exports.run = async (client, message, args) => {
const username = message.mentions.members.first().user.username; //gets the first mentioned users username
let member = message.mentions.members.first();
if (!member) return message.reply("Please mention a valid member of this server");
if (!member.kickable) return message.reply("I cannot kick this member!");
const reason = args.slice(1).join(" ");
const kickedmessage = new MessageEmbed() //embed to send to a logs channel
.setColor("#1773BA")
.setTitle("User Kicked")
.setDescription(username + "had been kicked for " + reason);
client.channels.cache.get("771835493305286688").send(kickedmessage); //output the embed
member.kick(reason);
};
I try to send a Message in a Server. This Server ID is logged in MongoDB and the Channel ID too. But everytime i'll try it, it does not working. Here's my Code:
The Error is the return console.log Text
//This is the guildMemberUpdate file
const client = require("../index.js")
const {MessageEmbed} = require("discord.js")
const {RED, GREEN, BLUE} = require("../commands/jsons/colors.json")
const Schema = require("../models/StatusTracker.js")
client.on("guildMemberUpdate", async(member) => {
const data = await Schema.findOne({Guild: member.guild.id})
let channel = member.guild.channels.cache.get(data.Channel)
if(!channel) return console.log("Es wurde kein Channels gefunden");
if(member.user.presence.status === "offline") {
let offlineEmbed = new MessageEmbed()
.setColor(RED)
.setDescription(member.user.toString() + " ist jetzt offline!")
.setAuthor(member.user.tag, member.user.avatarURL({ dynamic: true }))
channel.send(offlineEmbed)
} else if(member.user.presence.status === "dnd" || member.user.presence.status === "online" || member.user.presence.status === "idle"){
let onlineEmbed = new MessageEmbed()
.setColor(GREEN)
.setDescription(member.user.toString() + " ist jetzt online!")
.setAuthor(member.user.tag, member.user.avatarURL({ dynamic: true }))
channel.send(onlineEmbed)
}
})```
//This is the MongoDB File
"Guild": "851487615358337065",
"Channel": "859444321975009290"
The problem is that you're using the guildMemberUpdate event, but that only tracks nickname and role changes. The one that you're looking for is presenceUpdate. That'll trigger when any user goes offline etc.
Check the docs for more details: here
Note: You'll probably need to enable 'Presence intent' in 'Privileged Gateway Intents' in your bot's settings page for this to work. (https://discord.com/developers/applications)
As in the question, I have a problem with a bot that won't add ranks, I don't know why, I think I'm doing everything right.
bot.on('guildMemberAdd', guildMember => {
WelcomeUser(guildMember)});
The bot only sends an embed to the welcome chat, but does not rank the user
function WelcomeUser(usr){
usr.roles.add(userRoleID);
let welcomeChan = bot.channels.cache.find(channel => channel.id === welcomeChanID);
let userAvatar = usr.user.avatarURL();
const embed = new Discord.MessageEmbed()
.setTitle(usr.user.tag + " welcome in our server!")
.setColor("#ffff00")
.setThumbnail(userAvatar)
.setFooter('RollerBot by flanktus', "https://i.imgur.com/M2NNoC9.png")
.setDescription("We hope you will have a nice time");
welcomeChan.send(embed);
welcomeChan.send(`${usr.user}`)
}
i am tring to do that every time someone that joins my server blocks dms the bot will open a channel and send a verify link instead of a dm
what I stuck on (store the channel and stuff like that)
client.on('guildMemberAdd', member => {
const linkId = pool.createLink(member.id);
const embed = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`To gain access to this server you must solve a captcha. The link will expire in 15 minutes.\nhttp://${domain == '' ? 'localhost:8050' : domain}/verify/${linkId}`)
.setColor('YELLOW');
channel = client.channels.cache.get(`${logschannel}`);
channel.send('user has joined if you dont get another message in a few minutes please check if the user has verifyed ');
member.send(embed).catch(() => {message.guild.channels .create(member.id, { type: "text" }), channel.send('#here'); const errore = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`The user with the id ${member.id} is blocking dms please check on that!`)
.setColor('RED')
channel.send(errore)})
what I had
client.on('guildMemberAdd', member => {
const linkId = pool.createLink(member.id);
const embed = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`To gain access to this server you must solve a captcha. The link will expire in 15 minutes.\nhttp://${domain == '' ? 'localhost:8050' : domain}/verify/${linkId}`)
.setColor('YELLOW');
channel = client.channels.cache.get(`${logschannel}`);
channel.send('user has joined if you dont get another message in a few minutes please check if the user has verifyed ');
member.send(embed).catch(() => {channel.send('#here'); const errore = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`The user with the id ${member.id} is blocking dms please check on that!`)
.setColor('RED')
channel.send(errore)})
To create the channel you can just use GuildChannelManager#create (aka guild.channels.create).
member.guild.channels.create(`${member.author.username}-verification`, {
permissionOverwrites: [
{
id: member.author.id,
allow: ['VIEW_CHANNEL'],
},
{
id: member.guild.id,
deny: ['VIEW_CHANNEL'],
},
]
});
To send a message to the channel there are two ways you can do it.
A: Store the channel object.
const verifyChannel = member.guild.channels.create(`channel`);
verifyChannel.send('Message!')
B: Use .then() as creating as channel returns a promise.
member.guild.channels.create(`channel`)
.then(chan => {
chan.send('Message!');
});
I have no idea what I’m doing. I don’t code but my friend helped me out up to this part
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('This Bot is online!');
client.user.setActivity('Prefix +k')
});
client.on('message', msg=>{
if(msg.content === "+k Hello"){
msg.reply('Welcome!');
}
})
client.on('message', msg=>{
if(msg.content === "+k Credits"){
msg.reply('Pokemon DB for Info, MrTechGuy for code help!');
}
})
client.on('message', msg=>{
if(msg.content === "+k Credits"){
msg.reply('Pokemon DB for Info, MrTechGuy for code help!');
}
})
client.on('message', msg=>{
if(msg.content === "+k DAList"){
msg.reply('1 - Butterfree <:V:750540886680666282> <:grass:750540661396340826>, 2 = Butterfree <:VMAX:750540886701637743> <:grass:750540661396340826>,');
}
})
client.login('[REDACTED]');
Again, how would I add a hug command that targets the user, e.g. +k hug #user 1, my friend is out for the month and I do not know how to do it
response: #user 2 hugged #user 1 ! (gif here)
For this to work you will need to create a folder named "hug" and with images which are "gif".
if(message.content.startsWith('+k hug')) {
let user = msg.mentions.users.first(); // refers to the user you wish to mention
if (!user) {
let maxImageNumber1 = 7; // represents the number of images in the folder
let hug = Math.floor(Math.random() * (maxImageNumber1 - 1 + 1)) + 1;
let imageName1 = `${hug}.gif` // if the images you put are png/jpg just remove the ".gif" with either ".png" or ".jpg"
let imagePath1 = `/hug/${imageName1}` // folder name
let file1 = new Discord.MessageAttachment(imagePath1);
let embed1 = new Discord.MessageEmbed();
embed1.setImage(`attachment://${imageName1}`)
embed1.setDescription(`**${msg.author.username}** hugged their clone`)
embed1.setColor('RANDOM')
msg.channel.send({ files: [file1], embed: embed1 });
}
if (user) {
let maxImageNumber1 = 7; // represents the number of images in the folder
let hug = Math.floor(Math.random() * (maxImageNumber1 - 1 + 1)) + 1;
let imageName1 = `${hug}.gif` // if the images you put are png/jpg just remove the ".gif" with either ".png" or ".jpg"
let imagePath1 = `/hug/${imageName1}` // folder name
let file1 = new Discord.MessageAttachment(imagePath1);
let embed1 = new Discord.MessageEmbed();
embed1.setImage(`attachment://${imageName1}`)
embed1.setDescription(`**${msg.author.username}** hugged **${user.username}**`)
embed1.setColor('RANDOM')
msg.channel.send({ files: [file1], embed: embed1 });
}
}
Im assuming you are using discord.js v12
TIP:
I'd recommend you define your prefix with something like const prefix = '+k'; and when you want to make a command do this: if(message.content.startsWith(prefix + 'hug')){}