This is my code of adding an emoji, I've defined Reason of adding emoji from argument 1, the argument is noted but it is not added to the audit logs as emoji creation reason...
const Discord = require('discord.js');
module.exports = {
name: "add-emoji",
aliases: [],
description: "to steal an emoji",
usage: "add-emoji <emoji>",
run: async (client, message, args) => {
try {
let emojiId;
let emojiType;
let emojiName;
if(args[0].includes("<")) emojiId = args[0].match(/\d{15,}/g)[0]; //gets emoji id
if(args[0].includes("<a:")) emojiType = 'gif'; //gets type of emoji
if(args[0].includes("<:")) emojiType = 'png'; //gets type of emoji
if(args[0].includes("<:")) emojiName = args[0].replace(emojiId, '')
.replace(/[<]/gi, '')
.replace(/[>]/gi, '')
.replace(/[:]/gi, '') //gets emoji name
if(args[0].includes("<a:")) emojiName = args[0].replace(emojiId, '')
.replace(/[<]/gi, '')
.replace(/[a]/gi, '')
.replace(/[>]/gi, '')
.replace(/[:]/gi, '') //gets emoji name
let emojiLink = `https://cdn.discordapp.com/emojis/${emojiId}.${emojiType}`;
if(!args[0].includes("<")) return message.channel.send({ content: `:x: Mention a emoji!` });
let Reason = args.slice(1).join(" ");
if(!Reason) Reason = "No reason provided!";
await message.guild.emojis.create(emojiLink, emojiName, Reason).then( async emoji => {
let embed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setTitle("New emoji added!")
.setDescription(`EmojiName: ${emoji.name} \nEmoji: ${emoji} \nEmoji Id: ${emoji.id} \nAdded by ${message.author.tag}`)
message.channel.send({ embeds: [embed] });
});
} catch(e) {
console.log(e);
}
}
};
I've tried like discord.js v14 but it's not even creating emoji:
await message.guild.emojis.create({ attachment: emojiLink, name: emojiName, reason: Reason })
simply just write reason variable in bracket {} and write reason:
before variable.
Solution:
await message.guild.emojis.create(emojiLink, emojiName, { reason: Reason })
here's your whole code:
const Discord = require('discord.js');
module.exports = {
name: "add-emoji",
aliases: [],
description: "to steal an emoji",
usage: "add-emoji <emoji>",
run: async (client, message, args) => {
try {
let emojiId;
let emojiType;
let emojiName;
if(args[0].includes("<")) emojiId = args[0].match(/\d{15,}/g)[0]; //gets emoji id
if(args[0].includes("<a:")) emojiType = 'gif'; //gets type of emoji
if(args[0].includes("<:")) emojiType = 'png'; //gets type of emoji
if(args[0].includes("<:")) emojiName = args[0].replace(emojiId, '')
.replace(/[<]/gi, '')
.replace(/[>]/gi, '')
.replace(/[:]/gi, '') //gets emoji name
if(args[0].includes("<a:")) emojiName = args[0].replace(emojiId, '')
.replace(/[<]/gi, '')
.replace(/[a]/gi, '')
.replace(/[>]/gi, '')
.replace(/[:]/gi, '') //gets emoji name
let emojiLink = `https://cdn.discordapp.com/emojis/${emojiId}.${emojiType}`;
if(!args[0].includes("<")) return message.channel.send({ content: `:x: Mention a emoji!` });
let Reason = args.slice(1).join(" ");
if(!Reason) Reason = "No reason provided!";
await message.guild.emojis.create(emojiLink, emojiName, { reason: Reason }).then( async emoji => {
let embed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setTitle("New emoji added!")
.setDescription(`EmojiName: ${emoji.name} \nEmoji: ${emoji} \nEmoji Id: ${emoji.id} \nAdded by ${message.author.tag}`)
message.channel.send({ embeds: [embed] });
});
} catch(e) {
console.log(e);
}