'Discord JS v12 Add Field Issues
let xp = db.get(`xpchannel_${message.guild.id}`)
let wel = db.get(`welchannel_${message.guild.id}`)
let px = db.get(`prefix_${message.guild.id}`)
let defaultprefix = '.'
let disabled = ':white_circle: Disabled'
let embed = new Discord.MessageEmbed()
.setColor(ee.color)
.setAuthor('Database Settings', client.user.avatarURL())
.setThumbnail(ee.thumbnail)
.addFields(
{ name: '__**XP Channel**__', value: `${xp || `${disabled}`}`, inline: true },
{ name: '__**Welcomer Channel**__', value: `${wel || `${disabled}`}`, inline: true },
{ name: '__**Set Prefix**__', value: `\`${px || `${defaultprefix}`}\``, inline: true },
)
if (!message.member.permissions.has('ADMINISTRATOR')) {
return message.channel.send("<:warning:943421375526355024> | **You Need `ADMINISTRATOR` Permissions To Use This Command!**");
}
message.channel.send(embed)
Whenever I use this command and theres a xp channel or welcomer channel in the database it returns the channel id instead of the channel itself, I have tried to fix this by adding <# > at the front and end of the variable but then when theres no channel in the database it returns <#null> instead of the disabled variable. How would i fix that?
Solution 1:[1]
You should check if the values of those variables (xp and wel) are truthy. If they are, the channel ID is returned from the database, you can squeeze them beetween <# and >. If the returned value is null, you can simply pass the disabled variable:
.addFields(
{
name: '__**XP Channel**__',
value: xp ? `<#${xp}>` : disabled,
inline: true,
},
{
name: '__**Welcomer Channel**__',
value: wel ? `<#${wel}>` : disabled,
inline: true,
},
{
name: '__**Set Prefix**__',
value: `\`${px || defaultprefix}\``,
inline: true,
},
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zsolt Meszaros |
