Line separator/break in discord embded - javascript

I have the following discord embed:
message.reply({
content: '',
embed: {
color: 11416728,
author: {
name: 'xx know-it-all',
icon_url: 'https://xx.png'
},
description: '',
footer: {
icon_url: client.user.avatarURL,
text: '© xx Network'
},
fields: [
{
name: '1st Line',
value: '2nd Line',
},
{
name: 'MAKE THIS JUST A SPACER',
value: 'MAKE THIS JUST A SPACER',
},
{
name: '5th Line',
value: '6th Line',
}
]
}
})
I am trying to figure out how to create a spacer of sorts. I have tried using a html space, blank space, and alt code space. None of them seem to work. Any ideas on how to accomplish this?
The issue is discord is returning the field as null, so it's not taking it when I use the invisible html space or putting \n

I got it!
All I needed to do was use the C/C++/Java encoding version of the invisible space
\u200B
Reference: https://www.fileformat.info/info/unicode/char/200B/index.htm
This can come into use for other people looking to make embeds look more clear as discord complicates it

Discord.JS has a method .addEmptyField() that uses \u200B to display a empty line.
message.reply({
content: '',
embed: {
color: 11416728,
author: {
name: 'xx know-it-all',
icon_url: 'https://xx.png'
},
description: '',
footer: {
icon_url: client.user.avatarURL,
text: '© xx Network'
},
fields: [
{
name: '1st Line',
value: '2nd Line',
},
{
name: '\u200B',
value: '\u200B',
},
{
name: '5th Line',
value: '6th Line',
}
]
}
})
Appears to be working here.

Interestingly, I figured out you can get around this by using the backspace escape-sequence too:
\b
This is useful if you want your embed fields formatted in a 2 x 2:
fields: [
{
name: 'Field1',
value: 'Value1',
inline: true
},
{
name: 'Field2',
value: 'Value2',
inline: true
},
{
name: '\b',
value: '\b',
inline: true
},
{
name: 'Field3',
value: 'Value3',
inline: true
},
{
name: 'Field4',
value: 'Value4',
inline: true
},
]

Related

uncaught TypeError TypeError: Cannot read properties of null (reading 'send')

Whenever my bot is added to a discord server it crashes. This is the code I use for the guild join message:
client.on('guildCreate', guild => {
const exampleEmbed = {
color: 0x0099ff,
title: 'Some title',
url: 'https://discord.js.org',
author: {
name: 'Some name',
icon_url: 'https://i.imgur.com/AfFp7pu.png',
url: 'https://discord.js.org',
},
description: 'Some description here',
thumbnail: {
url: 'https://i.imgur.com/AfFp7pu.png',
},
fields: [
{
name: 'Regular field title',
value: 'Some value here',
},
{
name: '\u200b',
value: '\u200b',
inline: false,
},
{
name: 'Inline field title',
value: 'Some value here',
inline: true,
},
{
name: 'Inline field title',
value: 'Some value here',
inline: true,
},
{
name: 'Inline field title',
value: 'Some value here',
inline: true,
},
],
image: {
url: 'https://i.imgur.com/AfFp7pu.png',
},
timestamp: new Date(),
footer: {
text: 'Some footer text here',
icon_url: 'https://i.imgur.com/AfFp7pu.png',
},
};
guild.systemChannel.send({ embeds: [exampleEmbed] });
});
Does anyone know how I can fix the code to make it work (embed is an example from discord.js that should work)
If you check the documentation, you can see that systemChannel can be null so you'll need to check it first.
Another option is to check if there is a channel with the name general and send it there:
// ...
if (guild.systemChannel)
return guild.systemChannel.send({ embeds: [exampleEmbed] });
let channel = guild.channels.cache.find(
(ch) => ch.name.toLowerCase() === 'general'
);
if (channel)
return channel.send({ embeds: [exampleEmbed] });
// ...

Loop through array of objects, if value exists, return another value

With the information below I am trying loop through cards, if there is a nested object of helper, return that objects title. But am either receiving undefined or errors. I was thinking maybe reduce would be viable here?
Sample Array:
cards: [
0: {
title: 'Something',
logo: 'logo link here',
},
1: {
title: 'Something 2',
logo: 'logo link here',
helper: {
text: 'helper text',
},
},
2: {
title: 'Something 3',
logo: 'logo link here',
},
]
code:
cards.filter((item) => {
if (item.helper) setHelperActive({...helperActive, item.title: true})
})
let cards = [
{
title: 'Something',
logo: 'logo link here',
},
{
title: 'Something else',
logo: 'logo link here',
helper: {
text: 'helper text',
},
},
{
title: 'Something',
logo: 'logo link here',
},
{
title: 'Lorem Epsum',
logo: 'logo link here',
helper: {
text: 'helper text',
},
}
]
let filtered = []
for(let i = 0; i < cards.length; i++) {
if(cards[i].helper) {
filtered.push(cards[i].title)
}
}
console.log(filtered);
Using .filter() and checking if the object has a prop named helper. In case of multiple objects matching the criteria, their title's will be joined as a comma-separated string.
Snippet
let cards = [
{
title: 'Something',
logo: 'logo link here',
},
{
title: 'Something 2',
logo: 'logo link here',
helper: {
text: 'helper text',
},
},
{
title: 'Something',
logo: 'logo link here',
},
{
title: 'Something 4',
logo: 'logo link here',
helper: {
text: 'helper text',
},
},
]
// to list titles from all matching objects as a comma-separated string
console.log(cards.filter(ob => 'helper' in ob).map(({ title }) => title).join());
// suppose only the first matched object's title is required
console.log(cards.find(ob => 'helper' in ob)?.title ?? 'no match found');
the solution is to use map not filter should be like this:
var titles = cards.map(card=>{ return card.title })

How to make an embed without a title or description Discord.js

I am trying to make an embed for a commission but when I try making the embed's title and description "\u200b".. it is giving a space. What would I do in this situation?
my try at it
example image
embed:
const embed = {
title: `\u200b`,
description: `\u200b`,
author: {icon_url: "https://cdn.discordapp.com/icons/776700748494012427/9d95fa1d5e160032dff0b7f78953dc81.webp?size=128", name: "Camp Atoka's membercount"},
fields: [
{
name: 'Members',
value: `${message.guild.memberCount}`,
inline: true
},
{
name: 'Goal',
value: `${goal}`,
inline: true
},
{
name: 'Left',
value: `${goal-message.guild.memberCount}`,
inline: true
},
],
thumbnail: {url: "https://cdn.discordapp.com/icons/776700748494012427/9d95fa1d5e160032dff0b7f78953dc81.webp?size=128"}
}
Looks like you don't want those fields (title, description) to show up at all, couldn't you just remove them?
Discord Guide doesn't seem to explicit say anywhere that those are needed, there are only limitations to their sizes.

How do I adapt a javascript to use a database input?

I am a novice Java/CSS/HTML user with a background using SQL. For a personal website project, I want to connect a webpage i am building to a database list of questions. Currently, the questions I am using are just written in the javacode like such:
const questions = [{
question: 'What is 2 + 2?',
answers: [
{ text: '4', correct: true },
{ text: '22', correct: false },
{ text: '2.2', correct: false },
{ text: '57', correct: false }
]
},
{
question: 'What is the captial of Russia?',
answers: [
{ text: 'Helsinki', correct: false },
{ text: 'St Petersburg', correct: false },
{ text: 'Moscow', correct: true },
{ text: 'Sainsburys', correct: false }
]
},
{
question: 'How many sides does a nonagon have',
answers: [
{ text: 'As many as it wants', correct: false },
{ text: 'Nine', correct: true },
{ text: 'Seven', correct: false },
{ text: 'Twelve', correct: false }
]
},
{
question: 'What is 4 * 2?',
answers: [
{ text: '6', correct: false },
{ text: '8', correct: true },
{ text: '10', correct: false },
{ text: '12', correct: false }
]
}
]
Instead of using this hideous list, I would like to use a connection to information I have in a amazon-DynamoDB database which has 50 or so questions listed.
My question is:
What would replace the code above to create a connection to the database and to use the new data the same way?
I can reformat the sql database data to have columns: Question, Answer, Correct? in preperation
Any help would be fantastic, I've gone a bit off grid from the training material I was using!
removed question about looking for a database recommendation

How to group 2 groups into 1 group in Extjs grid?

I have this grid and would like to group 2 groups into a single group based on the status. Basically I want to put together "Cheched-In" and "Ready for MA" into a single group. Thanks a lot for the help!
Here's the working code: FIDDLE
Ext.create('Ext.grid.Panel', {
title: 'Employees',
store: store,
columns: [
{ text: 'Box', dataIndex: 'box', width: 50 },
{ text: 'Name', dataIndex: 'name', flex: 2 },
{ text: 'Status', dataIndex: 'status', flex: 1 }
],
features: [{ftype:'grouping'}],
renderTo: Ext.getBody()
});
You can try to have a different field for grouping, try this
function addGroupField(data) {
return data.map(function(row) {
return {
box: row.box,
name: row.name,
status: row.status,
groupedStatus: [
'Checked-In',
'Ready for MA'
].indexOf(row.status) > -1 ? 'Checked-In & Ready for MA' : row.status,
}
});
}
var data = addGroupField([
{ box: '', name: 'Brady, Marsha',status: 'Checked-In' },
{ box: 'MA', name: 'Dwight, Schrute', status: 'With MA' },
{ box: 'MA', name: 'Jim, Halpert', status: 'With MA' },
{ box: 'MA', name: 'Mike, Brown', status: 'With MA' },
{ box: 'MA', name: 'Steve, Smith', status: 'With MA' },
{ box: 'MA', name: 'Lori, Morrison', status: 'With MA' },
{ box: 'MA', name: 'Mary, Loson', status: 'With MA' },
{ box: 'MA', name: 'Junior, Meloni', status: 'With MA' },
{ box: 'MA', name: 'Jim, Halpert', status: 'With MA' },
{ box: '', name: 'Kevin, Malone', status: 'Checked-In' },
{ box: '', name: 'Angela, Martin', status: 'Checked-In' },
{ box: '2', name: 'Jim, Halpert', status: 'Ready for MA' },
{ box: '2', name: 'Kevin, Malone', status: 'Ready for MA' },
{ box: '2', name: 'Angela, Martin', status: 'Ready for MA' }
]);
var store = Ext.create('Ext.data.Store', {
fields: ['name', 'seniority', 'department'],
groupField: 'groupedStatus',
data: data
});
Ext.onReady(function() {
Ext.create('Ext.grid.Panel', {
title: 'Employees',
store: store,
columns: [
{ text: 'Box', dataIndex: 'box', width: 50 },
{ text: 'Name', dataIndex: 'name', flex: 2 },
{ text: 'Status', dataIndex: 'status', flex: 1 }
],
features: [{ftype:'grouping'}],
renderTo: Ext.getBody()
});
});

Categories

Resources