When someone adds an emoji to the server, the bot will log it. I'm trying to make it where it will but the emoji in the thumbnail of the log embed. Whenever it trys to log, I get the error..
[15:55:28] [UTC June:10:2021] [ERROR] (node:11176) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body embed.thumbnail.url: Scheme "undefined" is not supported. Scheme must be one of ('http', 'https'). embeds[0].thumbnail.url: Scheme "undefined" is not supported. Scheme must be one of ('http', 'https').
I'm guessing that the code for the thumbnail is returned undefined and you can't put that into a thumbnail. My code is
const Discord = require("discord.js")
exports.run = async(client) => {
client.on("emojiCreate", function(emoji){
console.log(emoji)
const Embedf = new Discord.MessageEmbed()
.setColor("#1CDEA3")
.setTitle('New Emoji Created')
.addFields(
{ name: 'Emoji Name:', value: emoji.name, inline: false },
{ name: 'Emoji ID:', value: emoji.id, inline: false },
{ name: 'Nitro Emote?', value: emoji.animated, inline: false })
.setThumbnail(`${emoji.icon}`)
.setFooter(`${emoji.guild.name}`)
.setTimestamp()
client.channels.cache.find(channel => channel.id == "851987273837969408").send(Embedf)
})
}
How can I fix this? Thanks
A GuildEmoji does not have an icon property.
You may have meant to use the url property.
const Embedf = new Discord.MessageEmbed()
.setColor("#1CDEA3")
.setTitle('New Emoji Created')
.addFields(
{ name: 'Emoji Name:', value: emoji.name, inline: false },
{ name: 'Emoji ID:', value: emoji.id, inline: false },
{ name: 'Nitro Emote?', value: emoji.animated, inline: false })
.setThumbnail(emoji.url) // use URL instead of icon
.setFooter(emoji.guild.name)
.setTimestamp()
Related
const {Client, CommandInteraction, MessageEmbed} = require("discord.js");
const db = require("../../Structures/Schemas/InfractionDB");
module.exports = {
name: "warnings",
description: "Give a warning",
permission: "ADMINISTRATOR",
options: [
{
name: "target",
description: "Select a target.",
type: "USER",
required: true
},
{
name: "reason",
description: "Provide a reason.",
type: "STRING",
required: true
},
{
name: "evidence",
description: "Provide evidence.",
type: "STRING",
required: false
},
],
/**
*
* #param {CommandInteraction} interaction
* #param {Client} client
*/
execute(interaction, client) {
const{guild, member, options} = interaction
const Target = options.getMember("target");
const Reason = options.getString("reason");
const Evidence = options.getString("evidence") || "None provided";
const Response = new MessageEmbed()
.setColor("RED")
.setAuthor({name: "MOD BOT", iconURL: guild.iconURL()});
db.findOne({GuildID: guild.id, UserID: Target.id}, async (err,data)=> {
if(err) throw err;
if(!data || !data.WarnData) {
data = new db({
GuildID: guild.id,
UserID: Target.id,
WarnData: [
{
ExecuterID: member.id,
ExecuterTag: member.user.tag,
TargetID: Target.id,
TargetTag: Target.user.tag,
Reason: Reason,
Evidence: Evidence,
Date: parseInt(interaction.createdTimestamp / 1000)
}
],
})
} else {
const WarnDataObject ={
ExecuterID: member.id,
ExecuterTag: member.user.tag,
TargetID: Target.id,
TargetTag: Target.user.tag,
Reason: Reason,
Evidence: Evidence,
Date: parseInt(interaction.createdTimestamp / 1000)
}
data.WarnData.push(WarnDataObject)
}
data.save()
});
Response.setDescription(`Warning Added: ${Target.user.tag} | ||${Target.id}||\n**Reason**: ${Reason}\n**Evidence**:${Evidence}`);
guild.channels.cache.get("946217387336818699").send({embeds:[Response]});
}}
originally this was routed to a different collection in my db. I've tried to convert it so I can see everything in one place. but it's taken me hours and don't seem to be getting anywhere. Like I said, the data is being stored on the db, but the Response is failing. Any ideas how to fix this? There are no errors in terminal
The error i think is that your application is taking too long to respond.
you have only 3 seconds to respose.
for this i would suggest that you execute you interaction as a async function
and you should use await before trying to find it in the database. because it can take some time to find the data in the database.
The data is store in database because it has no concern with the response time but the discord api wants a reply in 3 seconds or it will fail.
I have read your code. it seems okay.
i would suggest you to use the easier way instead of using the object or json form to create the commands.
SlashCommandBuilder from #discordjs/builders
its easy to use and simple.
here is an example of how easy it is if you use SlashCommandBuilder
const { SlashCommandBuilder } = require('#discordjs/builders');
const data = new SlashCommandBuilder()
.setName('gif')
.setDescription('Sends a random gif!')
.addStringOption(option =>
option.setName('category')
.setDescription('The gif category')
.setRequired(true)
.addChoice('Funny', 'gif_funny')
.addChoice('Meme', 'gif_meme')
.addChoice('Movie', 'gif_movie'));
you can install all the dependencies using
npm install discord.js #discordjs/rest discord-api-types
first time posting here. I hope I've posted this correctly, but basically getting the error message "interaction.options.getMember is not a function" I've tried using getUser as well (someone suggested this) and it doesnt seem to fix the problem. I'm pretty new to all this so please go easy on me. as far as I can see everything has been defined correctly and I'm pretty sure the issue is from here somewhere as the rest of the commands work absolutely fine. Any help greatly appreciated!!
const { Client, CommandInteraction, MessageEmbed } = require("discord.js");
module.exports = {
name: "ban",
description: "Bans the target member",
permission: "ADMINISTRATOR",
options: [
{
name: 'target',
description: "Select a target to ban",
type: "USER",
required: true,
},
{
name: 'reason',
description: "Provide a reason for the ban",
type: "STRING",
required: true,
},
{
name: 'messages',
description: "Choose one of the choices",
type: "STRING",
required: true,
choices: [
{
name: "Don't delete any",
value: "0"
},
{
name: "Previous 7 days",
value: "7"
}
]
},
],
/**
*
* #param {Client} client
* #param {CommandInteraction} interaction
*/
execute(client, interaction) {
//ERROR IS LINE BELOW//
const Target = interaction.options.getMember('target');
if (Target.id === interaction.member.id)
return interaction.followUp({embeds: [new MessageEmbed().setColor("RED").setDescription(`⛔ You can't ban yourself.`)]})
if (Target.permissions.has("ADMINISTRATOR"))
return interaction.followUp({embeds: [new MessageEmbed().setColor("RED").setDescription(`⛔ You can't ban an administrator.`)]})
const Reason = interaction.options.getString('reason');
if (Reason.length > 512)
return interaction.followUp({embeds: [new MessageEmbed().setColor("RED").setDescription(`⛔ The reason cannot exceed 512 characters`)]})
const Amount = interaction.options.getString('messages')
Target.ban({days: Amount, reason: Reason})
interaction.followUp({embeds: [new MessageEmbed().setColor("GREEN").setDescription(`✅ **${Target.user.username}** has been banned!`)]})
}
}
According to your code, and per Discord API, you have your member (actually user) here:
name: 'target',
description: "Select a target to ban",
type: "USER",
required: true,
so that line should read
const Target = interaction.options.getUser('target');
You need to get the member by using the below code
const targetMember = interaction.guild.members.cache.find(member => member.id === Target)
The rest needs to change Target to targetMember or simplify with example below:
if (targetMember.permissions.has(Permissions.FLAGS.BAN_MEMBERS) || targetMember.user.bot || targetMember.user.id === interaction.user.id) {
return interaction.reply({
content: 'You are not authorized to ban this member or yourself.',
ephemeral: true
})
I actually managed to fix the issue before I went sleep at 4am. Essentially the problem was actually caused by the execute (client, interaction). In my other file, these parameters are (interaction, client). I also changed all instances of "followUp" with "reply" and it started working as intended.
Thanks for helping out though!
So simple emoji command where it's supposed to display it's information like name, id, link and etc you get the idea. Works all fine with default emojis and custom server emojis but the moment its animated the name changes from
"<a:CS_Shrug:740861064257863690>" to just ":CS_Shrug:" i know this has something with discord displaying stuff but is there anyway to get around this? People asked for code:
let args = msg.content.slice(PREFIX.length).trim().split(/ +/); //slice message in an array
if (args[1]) { //if theres something mentioned
let newRawdata = fs.readFileSync('./emojis.json');
let newData = JSON.parse(newRawdata);
var findEmoji = Object.values(newData).find(object => object === args[1]) //just a file with all unicode emojis bc yes
if (args[1].startsWith("<:") && args[1].endsWith(">")) { //custom server emoji
//not important code
} else if (args[1].startsWith("<a:") && args[1].endsWith(">")){
let ForBots = args[1]
let namever1 = ForBots.replace('<a','')
let namever2 = namever1.replace('>','')
let namever3 = namever2.split(':')
let name = namever3[1]
let id = namever3[2]
var inforEmbed2 = new Discord.MessageEmbed()
.setColor('#2ab94c')
.setTitle('Emoji information')
.addFields(
{ name: 'Type', value: "`Animated server emoji`", inline: false },
{ name: 'Name', value: "`"+name+"`", inline: false },
{ name: 'ID', value: "`"+id+"`", inline: true },
{ name: 'For bots', value: "`"+args[1]+"`", inline: true }, //should display `<a:CS_Shrug:740861064257863690>` but instead `:CS_Shrug:`
{ name: 'Emoji link', value: "https://cdn.discordapp.com/emojis/"+id+".gif?/v=1", inline: false },
)
.setThumbnail('https://cdn.discordapp.com/emojis/'+id+'.gif?/v=1')
.setFooter("C.U.A.L - Bot| ;help", 'https://cdn.discordapp.com/attachments/864287060424785941/872600493082415124/Avatar_1.png')
msg.channel.send(inforEmbed2)
} else if (findEmoji) { //default emoji
//more none important code
} else msg.reply("donno wtf this is") // wasnt an emoji
} else msg.reply("Gotta give me something first")
I want to have my status be "Watching" for command -help", but I don't know how to switch it from playing to watching,
Here is my code:
command(client, 'status', (message) => {
if (message.author.id != "my id goes here") return;
const content = message.content.replace('-status ', '')
client.user.setPresence({
activity: {
name: content,
type: 0,
},
})
})
You need to set the code :
client.user.setPresence({
status: 'online', //you can set online , idle , dnd and offline
activity: {
name: 'Some Name',
type: 'PLAYING', //here you can change it to 'WATCHING' , 'PLAYING' , STREAM,
url: 'https://discord.com'
}
});
For more info you can check here
I'm trying to make logs for my server, so when someone sends, deletes or edits a message, the bot will send an embed message in a specific channel with all the information. For some reason, the messageUpdate and messagedDelete events are triggered multiple times, and I can't understand why. I have tried everything, but nothing works. Why does this happen and how can I fix it?
I have the logs for each thing (sent, edited, deleted) in individual files, by the way. In my main file, this is the code I have for the messageUpdate:
bot.on('messageUpdate', (oldMessage, newMessage) => {
if (oldMessage.author.id === bot.user.id) return;
if(oldMessage.content === newMessage.content) return;
bot.events.get('editlogs').execute(oldMessage, newMessage);
})
This is my code for the edit logs:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.login(process.env.TOKEN);
module.exports = {
name: 'editlogs',
description: 'logs messages that were edited.',
category: 'logs',
execute(oldMessage, newMessage){
const logsChannel = bot.channels.cache.get("743142195594526822")
const logEmbed = new Discord.MessageEmbed()
.setColor('#ffa600')
.setTitle('Message Edited')
.setAuthor(oldMessage.author.tag, oldMessage.author.avatarURL())
.setThumbnail(oldMessage.author.avatarURL())
.addFields(
{ name: 'Old Message', value: oldMessage.content},
{ name: 'New Message', value: newMessage.content},
{ name: 'Channel', value: oldMessage.channel.toString(), inline: true },
{ name: 'Author', value: oldMessage.author, inline: true },
{ name: 'Author ID', value: oldMessage.author.id},
{ name: 'Message ID', value: oldMessage.id},
{ name: 'Message', value: '[Jump To Message](' + oldMessage.url + ')'},
)
.setTimestamp()
.setFooter('Edited in ' + oldMessage.guild.toString(), oldMessage.guild.iconURL());
logsChannel.send(logEmbed);
}}