I want to set guild icon as the thumbnail of embed but neither guild.icon nor guild.iconURL() work
bot.on('message', message => {
if(message.author.bot) return;
if(message.channel.name === 'verify') {
if(message.content === '!verify') {
message.delete()
let dm = message.author;
let server = message.guild.name;
let servericon = message.guild.iconURL();
console.log(servericon)
let attachment = new Discord.MessageAttachment(this.choose , 'chosen.png')
let embed = new Discord.MessageEmbed()
.setTitle(`**Welcome to ${server}**\n\nCaptcha`)
.setDescription("Please complete the captcha given below to gain access to the server.\n**Note:** This is case sensitive")
.setAuthor('Mr.Verifier', "https://i.ibb.co/nckjDjG/hmm.png")
.setThumbnail(servericon)
.addField(
{ name: '**Why all this?**', value: 'This is to protect the servers from\nmalicious raids of automated bots'}
)
.setImage(`attachment://chosen.png`)
dm.send(embed)
}else{
message.delete();
}
};
})
You need to use guild.iconURL().
Related
So i am trying to make a command that mute a member. I want my bot to check if there is role name Muted and if there is not, to create a role for Muted members.
This is the code:
module.exports = {
name: 'mute',
description: 'mutes a member',
execute(message, args, Discord, bot) {
let mutedRole = message.guild.roles.cache.find(r => r.name === 'Muted')
if(!mutedRole) {
Guild.roles.create({
data: {
name: 'Muted',
color: 'BLACK'
}
})
}
}
}
and the error is this:
C:\Users\ADRIAN\Desktop\ZerOne BOT\commands\mute.js:10
Guild.roles.create({
^
TypeError: Cannot read property 'create' of undefined
I don't think you should create a role via code. I think you should create a role in your Discord server (like actually just making one without code). Download the ms package. (npm i ms) Then, paste this code in:
const ms = require('ms');
module.exports = {
name: "mute",
description: "Mutes a member!",
execute(message, args, Discord, bot){
const target = message.mentions.users.first();
if (target) {
let mainRole = message.guild.roles.cache.find(role => role.name === 'Member');
let muteRole = message.guild.roles.cache.find(role => role.name === 'Muted');
let memberTarget = message.guild.members.cache.get(target.id);
if (!args[1]){
memberTarget.roles.remove(mainRole.id);
memberTarget.roles.add(muteRole.id);
message.channel.send(`<#${memberTarget.user.id}> has been muted.`);
return;
}
if (isNaN(args[1]) || !args[1] === ' '){
message.channel.send("Please enter a real number! (If you have a space after the username and you don\'t want to set a time limit, delete the space. YOU HAVE TO.)");
return;
}
memberTarget.roles.remove(mainRole.id);
memberTarget.roles.add(muteRole.id);
message.channel.send(`<#${memberTarget.user.id}> has been muted for ${ms(ms(args[1]))}`);
setTimeout(function(){
memberTarget.roles.remove(muteRole.id);
memberTarget.roles.add(mainRole.id);
}, ms(args[1]));
} else {
message.channel.send("Can't find that member!");
}
}
}
Thanks to CodeLyon for this code. Hope this works for you! It even includes a time limit.
format 1: !mute #User
format 2: !mute #User 1000 (1000 can be changed, just make sure it's in milliseconds)
module.exports = {
name: "unmute",
description: "Unmutes a member!",
execute(message, args, Discord, bot){
const target = message.mentions.users.first();
if (target) {
let mainRole = message.guild.roles.cache.find(role => role.name === 'Member');
let muteRole = message.guild.roles.cache.find(role => role.name === 'Muted');
let memberTarget = message.guild.members.cache.get(target.id);
memberTarget.roles.remove(muteRole.id);
memberTarget.roles.add(mainRole.id);
message.channel.send(`<#${memberTarget.user.id}> has been unmuted.`);
} else {
message.channel.send("Can't find that member!");
}
}
}
format: !unmute #User
Remember, this code only works if you have a role Member and a role Muted. So, in your server, add the role Member to everybody and add a role Muted (not to everybody).
Hope this works! If there's any need for clarification, please tell me in the comments.
So Hello again,
I am making a ticket bot for discord and I got this bug that I cannot solve it my self.
here's the create ticket command:
if(cmd === "new"){
const reason = message.content.split(" ").slice(1).join(" ");
if (message.guild.channels.exists("name", "ticket-" + message.author.username)) return message.channel.send(`You already have a ticket open.`);
message.guild.createChannel(`ticket-${message.author.username}`, "text").then(c => {
let role = message.guild.roles.find("name", "Support Team");
let role2 = message.guild.roles.find("name", "#everyone");
c.overwritePermissions(role, {
SEND_MESSAGES: true,
READ_MESSAGES: true
});
c.overwritePermissions(role2, {
SEND_MESSAGES: false,
READ_MESSAGES: false
});
c.overwritePermissions(message.author, {
SEND_MESSAGES: true,
READ_MESSAGES: true
});
var embedcreated = new Discord.RichEmbed()
.setColor("#f00202")
.setDescription(`You ticket has been created ` + message.guild.channels.find(channel => channel.name === c.name).toString())
.setTitle("Tickets | MiZ")
.setFooter(`Tickets System`)
.setTimestamp();
message.channel.send(embedcreated);
const embed = new Discord.RichEmbed()
.setColor("#f00202")
.addField(`Hey ${message.author.username}!`, ` Please explain your problen to the staff team.`)
.setTimestamp();
c.send({ embed: embed });
}).catch(console.error);
let sChannel = message.guild.channels.find(x => x.name === "logs");
if(!sChannel) return message.channel.send("logs channel not found.")
var staff = new Discord.RichEmbed()
.setColor("#f00202")
.addField("Created a ticket: " , message.author)
.setTitle("Logs | MiZ")
.setTimestamp();
sChannel.send(staff)
}
I have a line that checks if the channel exists but it doesn't work as I can create more tickets.
Used:
Discord.js: ^11.3.2
Please next time be more specific and use the javascript block code so it's more understandeble
no block code
"Javascript block code"
I'm having trouble creating a discord bot, what it should do is detect whenever someone jkoins a specific voice Chat, and if a user does, the bot would have to create a new channel with, as the name, the nickname of the user who joined, then move that user to the new created channel and set that channel to private so no one can join.
Currently my problems are:
-I can't set the name of the new channel as the nickname of the user
-I can't move the user to that channel
-And I think the rest may work
Here is the part of my code:
client.on('voiceStateUpdate', (oldMember, newMember) => {
if(newMember.channelID != '693086073244483614') return;
const nick = newMember.nickname;
newMember.guild.channels.create('test', { type: 'voice' })
.then(() => {
newMember.setChannel('test');
console.log(`Hello from ${newMember.channel}!`);
const nChannel = newMember.channel;
nChannel.setParent('690292158636360032');
nChannel.overwritePermissions([
{
parent: '#690292158636360032',
id: '532236212967047169',
deny: ['CONNECT'],
},
]);
});
});
Any help would be appriciated, I'm new to both discord bots and javascript, so thanks a lot!
The Client#voiceStateUpdate event does not return a member, it returns a VoiceState. https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-voiceStateUpdate
From the VoiceState, you can get a member with <VoiceState>.member.
So to fix your error, replace const nick = newMember.nickname to const nick = newMember.member.nickname.
client.on('voiceStateUpdate', (oldMember, newMember) => {
var oldUserChannel = oldMember.voiceChannel;
var newUserChannel = newMember.voiceChannel;
if(oldUserChannel === undefined && newUserChannel !== undefined) { //User joined the channel.
if(newMember.voiceChannel.id != '693086073244483614') return; //Check if the user join the right voice channel.
let nick = newMember.nickname;
if(nick == null){
nick = newMember.user.username; //If the member doesn't have a nickname.
}
newMember.guild.createChannel(nick, { type: 'voice' })
.then((nChannel) => {
console.log(`Hello from ${nChannel}!`);
nChannel.setParent('690292158636360032'); //Your category ID
nChannel.overwritePermissions(nChannel.guild.defaultRole.id, {
VIEW_CHANNEL: false
});
newMember.setVoiceChannel(nChannel)
});
} else if(newUserChannel === undefined){ //User left the channel.
if(oldMember.voiceChannel.parent == null) return;
if(oldMember.voiceChannel.parent.id != '690292158636360032') return; //Check if the voice channel is under the specified category.
if(oldMember.voiceChannel.members.first() == null){ //There is no more users in this channel.
oldMember.voiceChannel.delete(); //Delete the channel.
}
}
});
Here is the final result, fully working. I also add a system to automatically remove the channel if there is nobody in.
I have added some annotations, tell me if you have any questions.
Hello Stackoverflow community. I'm quite curious, regarding the channelUpdate event in Discord.js, is it possible to ignore some channels but log the rest?
bot.on("channelUpdate", async (oldChannel, newChannel) => {
// Get stat channel IDs
let totalUsers = oldChannel.guild.channels.get('667335552558956554');
let onlineUsers = oldChannel.guild.channels.get('667335645894541331');
let totalBots = oldChannel.guild.channels.get('667337560179343374');
//Leave the stat channels alone, or too much logging will happen
//.parent.id === '667335310350352394';
if (totalUsers || onlineUsers || totalBots) return;
let oldCategory = oldChannel.parent;
let newCategory = newChannel.parent;
let guildsChannel = newChannel.guild;
if (!newCategory) newCategory = "None";
if (!guildsChannel || !guildsChannel.available) return;
let types = {
"text" : "Text channel",
"voice" : "Voice channel",
"null" : "None"
};
const logchannel = channel.guild.channels.find(channel => channel.name === "server-logs")
if (!logchannel) return;
if (!logchannel.permissionsFor(oldChannel.guild.me).has('VIEW_CHANNEL')) return;
if (!logchannel.permissionsFor(oldChannel.guild.me).has('SEND_MESSAGES')) return;
if (oldChannel.name !== newChannel.name) {
let channelNameUpdateEmbed = new Discord.RichEmbed()
.setColor("#ffc500")
.setDescription("Channel name updated.")
.addField("Old channel name", `\`${oldChannel.name}\``, true)
.addBlankField(true)
.addField("New channel name", `\`${newChannel.name}\``, true)
.addField("Channel type", `${types[newChannel.type]}`, true)
.addBlankField(true)
.addField("Channel category", `${newCategory}`, true)
.setFooter(`Channel ID: ${newChannel.id} 🔥`)
.setTimestamp()
logchannel.send(channelNameUpdateEmbed).catch()
}
});
Those marked as so called "Stat channels", is it possible to ignore those? Else log channels will get flooded every time a member goes online or offline
Thanks in advance!
Sure, you can create ingoreChannel arr and check if channel in ignore arr.
Like this:
bot.on('channelUpdate', async (oldChannel, newChannel) => {
const ignoreChannels = ['667335552558956554', '667335645894541331', '667337560179343374'];
// Get stat channel IDs
if (ignoreChannels.includes(oldChannel.id)) return;
//Leave the stat channels alone, or too much logging will happen
//.parent.id === '667335310350352394';
let oldCategory = oldChannel.parent;
let newCategory = newChannel.parent;
let guildsChannel = newChannel.guild;
if (!newCategory) newCategory = 'None';
if (!guildsChannel || !guildsChannel.available) return;
let types = {
text: 'Text channel',
voice: 'Voice channel',
null: 'None',
};
const logchannel = channel.guild.channels.find(channel => channel.name === 'server-logs');
if (!logchannel) return;
if (!logchannel.permissionsFor(oldChannel.guild.me).has('VIEW_CHANNEL')) return;
if (!logchannel.permissionsFor(oldChannel.guild.me).has('SEND_MESSAGES')) return;
if (oldChannel.name !== newChannel.name) {
let channelNameUpdateEmbed = new Discord.RichEmbed()
.setColor('#ffc500')
.setDescription('Channel name updated.')
.addField('Old channel name', `\`${oldChannel.name}\``, true)
.addBlankField(true)
.addField('New channel name', `\`${newChannel.name}\``, true)
.addField('Channel type', `${types[newChannel.type]}`, true)
.addBlankField(true)
.addField('Channel category', `${newCategory}`, true)
.setFooter(`Channel ID: ${newChannel.id} 🔥`)
.setTimestamp();
logchannel.send(channelNameUpdateEmbed).catch();
}
});
Well, I followed "The Source Code" "discord.js" tutorial, (even copy-pasted his code from GitHub) but the ban and kick commands he's shown don't work, I assume they got broken by a recent update. It sends the embed to the incidents channel but doesn't actually ban the player. Also, if you have any suggestions for me to change things, please suggest!
if (cmd === `${prefix}ban`) {
let bUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if (!bUser) return message.channel.send("Can't find user!");
let bReason = args.join(" ").slice(22);
if (!message.member.hasPermission("MANAGE_MEMBERS")) return message.channel.send("No can do pal!");
if (bUser.hasPermission("MANAGE_MESSAGES")) return message.channel.send("That person can't be banned!");
let banEmbed = new Discord.RichEmbed()
.setDescription("Ban Management")
.setColor("#bc0000")
.addField("Banned User", `${bUser} with ID ${bUser.id}`)
.addField("Banned By", `<#${message.author.id}> with ID ${message.author.id}`)
.addField("Banned In", message.channel)
.addField("Time", message.createdAt)
.addField("Reason", bReason);
let incidentchannel = message.guild.channels.find(`name`, "incidents");
if (!incidentchannel) return message.channel.send("Can't find incidents channel.");
message.guild.member(bUser).ban(bReason);
message.delete().catch(O_o => {});
incidentchannel.send(banEmbed);
return;
}
message.guild.member(bUser).ban(bReason);
This will not ban the member. The message has a member property so you don't need to use message.guild.member you can just easily use message.member.
So it should look like this:
if (cmd === `${prefix}ban`) {
let bUser = message.guild.member(message.mentions.members.first() || message.guild.members.get(args[0]));
if (!bUser) return message.channel.send("Can't find user!");
let bReason = args.join(" ").slice(22);
if (!message.member.hasPermission("MANAGE_MEMBERS")) return message.channel.send("No can do pal!");
if (bUser.hasPermission("MANAGE_MESSAGES")) return message.channel.send("That person can't be banned!");
let banEmbed = new Discord.RichEmbed()
.setDescription("Ban Management")
.setColor("#bc0000")
.addField("Banned User", `${bUser.user.tag} with ID ${bUser.id}`)
.addField("Banned By", `<#${message.author.id}> with ID ${message.author.id}`)
.addField("Banned In", message.channel.name)
.addField("Time", message.createdAt)
.addField("Reason", bReason);
let incidentchannel = message.guild.channels.find(`name`, "incidents");
if (!incidentchannel) return message.channel.send("Can't find incidents channel.");
message.guild.member(bUser).ban({
reason: bReason
});
message.delete();
incidentchannel.send({
embed: banEmbed
});
return;
}
I changed a lot because a lot was outdated and could not work. It could be that I haven't seen one or the other mistake.
Let me know if it worked! :)
Best regards,
Monkeyyy11
This seems awfully complicated, I hope my command can make things a bit easier!
bot.on('message', message => {
const arguments = message.content.slice(prefix.length).trim().split(/ +/g);
const commandName = arguments.shift().toLowerCase();
if (message.content.startsWith(prefix) && commandName == "kick") {
if(!message.member.hasPermission("KICK_MEMBERS")) return message.channel.send("Permissions invalid");
const userKick = message.mentions.users.first();
if (userKick) {
var member = message.guild.member(userKick);
if (member) {
member.kick({
reason: `This person was kicked using a bot's moderation system. We are so sorry if this caused problems.`
}).then(() => {
message.reply(`A user been kicked.`)
})
} else {
message.reply(`User not found`);
}
} else {
message.reply(`Please enter a name`)
}}})
bot.on('message', message => {
const arguments = message.content.slice(prefix.length).trim().split(/ +/g);
const commandName = arguments.shift().toLowerCase();
if (message.content.startsWith(prefix) && commandName == "ban") {
if(!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send("Permissions invalid");
const userBan = message.mentions.users.first();
if (userBan) {
var member = message.guild.member(userBan);
if (member) {
member.ban({
reason: `This person was banned using a bot's moderation system. We are so sorry if this caused problems.`
}).then(() => {
message.reply(`a user has been banned!`)
})
} else {
message.reply(`User not found`);
}
} else {
message.reply(`Please enter a name`)
}}})
If you use discord.js v12 or higher, then RichEmbed is now deprecated. Instead, use MessageEmbed