hi please i need some help the bot is giving an error which is yourid , productownerid , productname is not defined in last steps i tried many codes but no one worked for me if anyone can help me please and thank you
if(interaction.customId == 'evv'){
let yourid = interaction.fields.getTextInputValue('ask_1')
let productownerid = interaction.fields.getTextInputValue('ask_2')
let productname = interaction.fields.getTextInputValue('ask_3')
let evalmsg = interaction.fields.getTextInputValue('ask_4')
const exampleEmbed = new MessageEmbed()
.setColor("RANDOM")
.setFields(
{ name: '**Buyer-Name**', value: `<#${yourid}>`}
{ name: '**Owner Of The Product**', value:`**<#${productownerid}>**`}
{ name: '**Product**', value:`**${productname}**`}
{ name: '**Message**', value: `**${evalmsg}**`}
)
.setFooter(`Requested By ${interaction.user.tag} , ${new Date()}`)
let button25 = new MessageActionRow().addComponents(
new MessageButton()
.setCustomId('1')
.setLabel("تقييم")
.setStyle('PRIMARY')
.setEmoji("💖")
)
await interaction.guild.channels.cache.get("1048414164932108289").send({embeds: [exampleEmbed],components:[button25]})
}
the error is from here :
if (interaction.customId == '1'){
const exampleEmbed2 = new MessageEmbed()
.setColor("RANDOM")
.setFields(
{ name: '**Buyer-Name**', value: `<#${yourid}>`}
{ name: '**Owner Of The Product**', value:`**<#${productownerid}>**`}
{ name: '**Product**', value:`**${productname}**`}
{ name: '**Message**', value: `**${evalmsg}**`}
{ name: '**Evaluation**', value: `**💖**`}
)
.setFooter(`Requested By ${interaction.user.tag} , ${new Date()}`)
interaction.guild.channels.cache.get("1048414164932108289").send({embeds: [exampleEmbed2],components:[]})
}
})```
Instead of using <#${yourid}>, you can use userMention(yourid) but i don't think it's the problem.
I think the probleme is the .setFooter for the date you don't have to do ${new Date()} there is a command for this : .setTimestamp().
Or another problem you can't put "RANDOM" in .setColor
And I use new EmbedBuilder() instead of messageEmbed()
You also have to put "," at the end of a field like this :
.setFields(
{ name: '**Buyer-Name**', value: `<#${yourid}>`},
{ name: '**Owner Of The Product**', value:`**<#${productownerid}>**`},
{ name: '**Product**', value:`**${productname}**`},
{ name: '**Message**', value: `**${evalmsg}**`},
{ name: '**Evaluation**', value: `**💖**`},
)
You also have to set a Title with .setTitle('title')
The last error i saw is for search a channel I use interaction.guild.channels.fetch('id')
So i propose you this correction :
if (interaction.customId == '1'){
const exampleEmbed2 = new EmbedBuilder()
.setTitle('title')
.setColor(15548997)
.addFields(
{ name: '**Buyer-Name**', value: userMention(yourid)},
{ name: '**Owner Of The Product**', value: '**' + userMention(productownerid) + '**'},
{ name: '**Product**', value:`**${productname}**`},
{ name: '**Message**', value: `**${evalmsg}**`},
{ name: '**Evaluation**', value: `**💖**`},
)
.setFooter(`Requested By ${interaction.user.tag}`)
.setTimestamp()
interaction.guild.channels.fetch("1048414164932108289").send({embeds: [exampleEmbed2]})
}
Related
I found that my command ended up needing many repeated options which were all similar. There are 4 players and 5 towers each and with my method it would take 20 separate inputs to address them all. This would be monotonous to input as the user and I was wondering if there was a way to simplify the inputting process for the user or just the code. I haven't found any direct solutions from the discord.js library.
Also, there is a built in limit of 25 options and I have gone over this amount.
Here is my initial attempt. Note that all the inputs use the same autocomplete options. Scroll to where it says //these lines
//party command
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('party')
.setDescription('Creates a party which others can join based on roles')
.addStringOption(option =>
option.setName('gamemode')
.setDescription('The name of the gamemode')
.setRequired(true)
.addChoices(
{ name: 'Hardcore', value: 'Hardcore' },
{ name: 'Fallen', value: 'Fallen' },
{ name: 'Molten', value: 'Molten' },
{ name: 'Normal', value: 'Normal' },
{ name: 'Badlands II', value: 'Badlands II' },
{ name: 'Polluted Wastelands II', value: 'Polluted Wastelands II' },
{ name: 'Pizza Party', value: 'Pizza Party' },
{ name: 'Other', value: 'Other' },
))
.addStringOption(option =>
option.setName('strategy')
.setDescription('The name of the strategy you will use - skip this option for no strategy ')
)
.addStringOption(option =>
option.setName('strategy-link')
.setDescription('The link to your strategy - skip this option for no strategy')
)
//these lines v
.addStringOption(option =>
option.setName('p1-1')
.setDescription('First tower for p1 - skip for no tower/player')
.setAutocomplete(true)
)
.addStringOption(option =>
option.setName('p1-2')
.setDescription('Second tower for p1 - skip for no tower/player')
.setAutocomplete(true)
),
// p1-3, p1-4, etc.
async autocomplete(interaction) {
const focusedOption = interaction.options.getFocused(true);
let choices;
if (focusedOption.name === 'p1-1', 'p1-2') {
//these lines ^
choices = [
'Scout',
'Sniper',
'Paintballer',
'Demoman',
'Soldier',
'Solder',
'Freezer',
'Hunter',
'Ace Pilot',
'Medic',
'Pyromancer',
'Farm',
'Militant',
'Shotgunner',
'Military Base',
'Rocketeer',
'Electroshocker',
'Commander',
'DJ Booth',
'Warden',
'Minigunner',
'Ranger',
'Accelerator',
'Engineer',
'Crook Boss',
'Turret',
'Mortar',
'Pursuit',
'Golden Minigunner',
'Golden Pyromancer',
'Golden Crook Boss',
'Golden Scout',
'Golden Cowboy',
'Golden Soldier',
'Frost Blaster',
'Swarmer',
'Toxic Gunner',
'Sledger',
'Executioner',
'Elf Camp',
'Archer',
];
}
const filtered = choices.filter(choice => choice.startsWith(focusedOption.value));
let options;
if (filtered.length > 25) {
options = filtered.slice(0, 25);
} else {
options = filtered;
}
await interaction.respond(
options.map(choice => ({ name: choice, value: choice })),
);
},
async execute(interaction) {
const gamemode = interaction.options.getString('gamemode');
const strategy = interaction.options.getString('strategy') ?? 'no';
await interaction.reply(`You created a party for ${gamemode} using ${strategy} strategy.`);
},
};
Node.js v18.12.1
npm list discord.js#12.5.3 dotenv#16.0.3
Thank you for your help.
I want to send this data as one embed message and I don't know how many of these we have.
I tried to do like this :
let list = hk;
var id = "";
var username = "";
var identifier = ""
for (var i = 0; i < list.length; i++) {
id += list[i].id + '\n';
username += list[i].user_name + '\n';
identifier += list[i].identifier + '\n';
}
const pListEmbed = new Discord.MessageEmbed()
.setColor('#03fc41')
.setTitle('Connected')
.setDescription(`Total : ${list.length}`)
.setThumbnail(config.logo)
.addFields({ name: 'ID', value: id, inline: true }, { name: 'Name', value: username, inline: true }, { name: 'Identifier', value: identifier, inline: true },
)
.setTimestamp(new Date())
.setFooter('Used by: ' + message.author.tag, `${config.SERVER_LOGO}`);
message.channel.send(pListEmbed);
});
but it sends several separate embed messages, each containing the data
and hk is this array that we don't know how many of the data we have
array :
[
{
id: '46892319372',
user_name: 'testerOne',
identifier: '20202'
}
]
[
{
id: '15243879678',
user_name: 'testerTwo',
identifier: '20201'
}
]
[
{
id: '02857428679',
user_name: 'testerThree',
identifier: '20203'
}
]
[
{
id: '65284759703',
user_name: 'testerFour',
identifier: '20204'
}
]
Simply use .forEach, that will loop over every single element and use the "addFields" method ->
// .setThumbnail()..
list.forEach(user => pListEmbed.addFields(
{ name: 'ID', value: user.id, inline: true },
{ name: 'Name', value: user.user_name, inline: true },
{ name: 'Identifier', value: user.identifier, inline: true }
))
message.reply({ embeds : [pListEmbed] })
you can map the array into the fields like this:
separate fields
.addFields(
array.flatMap(user => [
{ name: 'ID', value: user.id, inline: true },
{ name: 'Name', value: user.user_name, inline: true },
{ name: 'Identifier', value: user.identifier, inline: true }
])
)
single fields
.addFields(
array.flatMap(user => [
{ name: 'User', value: `${id + username + identifier}`, inline: true },
])
)
Why flatMap()?
flatMap() is an inbuilt function in JavaScript which is used to flatten the input array element into a new array. This method first of all map every element with the help of mapping function, then flattens the input array element into a new array.
exports.run = async (client, message, args) => {
let data = await cs.leaderboard(message.guild.id);
if (data.length < 1) return message.reply("Nobody's in leaderboard yet.");
const msg = new Discord.MessageEmbed();
let pos = 0;
// This is to get First 10 Users )
data.slice(0, 10).map(e => {
if (!client.users.cache.get(e.userID)) return;
pos++
msg.setColor('#0099ff')
msg.setTitle('Leaderboard')
msg.setAuthor({ name: 'Arkbuddies UK', iconURL: 'https://i.imgur.com/yHgaVv2.png', url: 'https://discord.js.org' })
msg.setThumbnail('https://i.imgur.com/yHgaVv2.png')
msg.addFields(
{ name: `${pos}\u200B\n`, value: `**${client.users.cache.get(e.userID).username}**`, inline: true },
{ name: `Wallet:`, value: `**${e.wallet}** <:Wishbone:939942552809902150>'s`, inline: true },
{ name: `Bank:`, value: `**${e.bank}** <:Wishbone:939942552809902150>'s`, inline: true},
)
msg.setTimestamp()
msg.setFooter({ text: 'Arkbuddies UK', iconURL: 'https://i.imgur.com/yHgaVv2.png' });
});
message.reply({
embeds: [msg]
}).catch();
}
exports.help = {
name: "leaderboard",
data: {
name: 'leaderboard',
description: "show's guild leaderboard.",
options: []
}
}
exports.conf = {
aliases: ["lb"],
cooldown: 5
}
case 'botinfo':
const botinfo = new Discord.MessageEmbed()
.addField("**Bot Name🤖:**", bot.user.username)
.setTitle("**Bot Information📄**")
.addFields(
{ name: '**Version⚙️ :**', value: bot.user.version },
{ name: '**Created by👤:**', value: ''},
{ name: '**Created at🗓:**', value: bot.user.createdAt},
{ name: '**help🛠:**', value: 'for more information about help with bot check text channel bothelp🛠'},
)
.setColor(0xF8F8F8)
.setThumbnail(bot.user.displayAvatarURL())
.addFooter("For More Embed Commands Type !embeds")
message.channel.send(botinfo);
break;
That is caused by addFooter() which is not a method, you need to use setFooter()
I am in the process of converting my bot to work with the master branch of discord.js
I got to my ticket command and they changed a lot, I managed to do everything apart from the overwritePermissions section. I am unsure of why the code is not working.
If I remove the bottom 2 overwritePermissions sections, it works fine, but with all 3 present, none execute.
let role = message.channel.guild.defaultRole;
let role2 = message.guild.roles.find(x => x.name === "Support Team");
message.guild.channels.create(`ticket-test`, {type: 'text'}).then(c => {
c.overwritePermissions({
permissionOverwrites: [{
id: role.id,
deny: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
}]
});
c.overwritePermissions({
permissionOverwrites: [{
id: role2.id,
deny: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
}]
});
c.overwritePermissions({
permissionOverwrites: [{
id: message.author.id,
allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
}]
});
});
I have done console.log(role.id) and console.log(role2.id and they both show the correct id, it's just not executing the code.
Instead of repeating the overwritePermissions() method, you can simply list your permission overwrites in the channel creation options in the first place. type's default is already a text channel, so you can also omit that option. Finally, you should always be catching Promises.
const everyone = message.guild.defaultRole;
const support = message.guild.roles.find(r => r.name === 'Support Team');
message.guild.channels.create('ticket-test', {
permissionOverwrites: [
{
id: everyone.id,
deny: 'VIEW_CHANNEL'
}, {
id: support.id,
allow: 'VIEW_CHANNEL'
}, {
id: message.author.id,
allow: 'VIEW_CHANNEL'
}
]
}).catch(err => console.error(err));
let role2 = message.guild.roles.find(x => x.name === "💻Mods");
but if you want
for this:
async function jointocreatechannel(user) {
//log it
console.log(" :: " + user.member.user.username + "#" + user.member.user.discriminator + " :: Created a Support")
//user.member.user.send("This can be used to message the member that a new room was created")
await user.guild.channels.create(`${user.member.user.username}'s Support`, {
type: 'voice',
parent: "973217461577080903", //or set it as a category id
}).then(async vc => {
//move user to the new channel
user.setChannel(vc);
//set the new channel to the map
jointocreatemap.set(`tempvoicechannel_${vc.guild.id}_${vc.id}`, vc.id);
//change the permissions of the channel
let role2 = message.guild.roles.find(x => x.name === "💻Mods");
await vc.overwritePermissions([
{
id: user.id,
allow: ['MANAGE_CHANNELS'],
},
{
id: user.guild.id,
deny: ['VIEW_CHANNEL'],
},
{
id: role2.id,
deny: ['VIEW_CHANNEL'],
},
]);
})
}
}