beck
DIAdiscord.js - Imagine a bot
•Created by beck on 8/4/2023 in #djs-questions
having a few issues with this command?
const { bold, SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const dayjs = require('dayjs');
const advancedFormat = require('dayjs/plugin/advancedFormat');
dayjs.extend(advancedFormat);
module.exports = {
data: new SlashCommandBuilder()
.setName('info')
.setDescription('Provides information about the user provided')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user to get information about')
.setRequired(true),
),
category: 'utility',
async execute(interaction) {
const isUser = interaction.options.getUser('user');
const fetchedUser = await isUser.fetch({ force: true });
const isMember = interaction.options.getMember('user');
const memberStatus = isMember?.presence?.status;
const statuses = {
online: 'https://cdn3.emoji.gg/emojis/5251-online-status.png',
idle: 'https://cdn3.emoji.gg/emojis/5505-idle-status.png',
dnd: 'https://cdn3.emoji.gg/emojis/5163-dnd-status.png',
offline: 'https://cdn3.emoji.gg/emojis/2179-offline-status.png',
};
const activities = {
1: 'Playing ',
2: 'Listening to ',
3: 'Watching ',
};
const activityName = isMember?.presence?.activities.find(activity => activity.type !== 4);
const memberInfo = new EmbedBuilder()
.setAuthor({ name: `${isUser.username} is ${memberStatus}!`, iconURL: statuses[memberStatus] })
.setTitle(bold((activities[activityName?.type] || 'Playing ') + (activityName?.name || 'nothing')))
.setColor(0x2d251f)
.setThumbnail(`${isUser.displayAvatarURL()}`)
.setDescription((isMember?.presence.activities.find(activity => activity.type === 4)?.state || 'Set a custom status!') + '\n')
.addFields(
{
name: bold('Information'), value: '> ' + bold('Name: ') + (isMember?.displayName || 'N/A') + '\n> ' + bold('Joined: ') + dayjs(`${isMember?.joinedAt}`).format('M/D/YYYY') + '\n> ' + bold('Created: ') + dayjs(`${isUser?.createdAt}`).format('M/D/YYYY') + '\n',
},
)
.setImage(`${fetchedUser?.bannerURL({ size: 1024 })}` ?? null)
.setFooter({ text: `Requested by ${isUser.username}`, iconURL: `${isUser.displayAvatarURL()}` });
if (isUser.bot) {
await interaction.reply({ content: 'That\'s a bot, moo!', ephemeral: true });
}
else if (memberStatus === 'dnd') {
memberInfo.setAuthor({ name: `${isUser.username} is on ` + (memberStatus.toUpperCase()) + '!', iconURL: statuses[memberStatus] });
await interaction.reply({ embeds: [memberInfo] });
}
else if (memberStatus) {
await interaction.reply({ embeds: [memberInfo] });
}
else {
await interaction.reply({ content: 'That user is not in this guild!', ephemeral: true });
}
},
};
const { bold, SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const dayjs = require('dayjs');
const advancedFormat = require('dayjs/plugin/advancedFormat');
dayjs.extend(advancedFormat);
module.exports = {
data: new SlashCommandBuilder()
.setName('info')
.setDescription('Provides information about the user provided')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user to get information about')
.setRequired(true),
),
category: 'utility',
async execute(interaction) {
const isUser = interaction.options.getUser('user');
const fetchedUser = await isUser.fetch({ force: true });
const isMember = interaction.options.getMember('user');
const memberStatus = isMember?.presence?.status;
const statuses = {
online: 'https://cdn3.emoji.gg/emojis/5251-online-status.png',
idle: 'https://cdn3.emoji.gg/emojis/5505-idle-status.png',
dnd: 'https://cdn3.emoji.gg/emojis/5163-dnd-status.png',
offline: 'https://cdn3.emoji.gg/emojis/2179-offline-status.png',
};
const activities = {
1: 'Playing ',
2: 'Listening to ',
3: 'Watching ',
};
const activityName = isMember?.presence?.activities.find(activity => activity.type !== 4);
const memberInfo = new EmbedBuilder()
.setAuthor({ name: `${isUser.username} is ${memberStatus}!`, iconURL: statuses[memberStatus] })
.setTitle(bold((activities[activityName?.type] || 'Playing ') + (activityName?.name || 'nothing')))
.setColor(0x2d251f)
.setThumbnail(`${isUser.displayAvatarURL()}`)
.setDescription((isMember?.presence.activities.find(activity => activity.type === 4)?.state || 'Set a custom status!') + '\n')
.addFields(
{
name: bold('Information'), value: '> ' + bold('Name: ') + (isMember?.displayName || 'N/A') + '\n> ' + bold('Joined: ') + dayjs(`${isMember?.joinedAt}`).format('M/D/YYYY') + '\n> ' + bold('Created: ') + dayjs(`${isUser?.createdAt}`).format('M/D/YYYY') + '\n',
},
)
.setImage(`${fetchedUser?.bannerURL({ size: 1024 })}` ?? null)
.setFooter({ text: `Requested by ${isUser.username}`, iconURL: `${isUser.displayAvatarURL()}` });
if (isUser.bot) {
await interaction.reply({ content: 'That\'s a bot, moo!', ephemeral: true });
}
else if (memberStatus === 'dnd') {
memberInfo.setAuthor({ name: `${isUser.username} is on ` + (memberStatus.toUpperCase()) + '!', iconURL: statuses[memberStatus] });
await interaction.reply({ embeds: [memberInfo] });
}
else if (memberStatus) {
await interaction.reply({ embeds: [memberInfo] });
}
else {
await interaction.reply({ content: 'That user is not in this guild!', ephemeral: true });
}
},
};
else
statement when a user is not in the guild to work (i've tried different things)
2. i'm unable to change the size of the bannerURL
now or change anything to do with the banner part or else the bot does not respond
3. no matter what i do i cannot if
out the banner if a user does not have one
i think the if
s are all over the place, but this was somehow the only way it would (mostly) function, mainly starting with my want to change the wording on the dnd prompt because for some reason it is really important to the order. i also tried my best not to make it a huge code so it is readable (for me) i'm not perfect at djs yet, so sorry 👍
also sorry if any of this is basic javascript, i'm autistic and have slower moments because of it4 replies
DIAdiscord.js - Imagine a bot
•Created by beck on 8/2/2023 in #djs-questions
don't know how to go about getting rid of this
26 replies
DIAdiscord.js - Imagine a bot
•Created by beck on 7/29/2023 in #djs-questions
many many errors
the code:
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { ActivityType } = require('discord.js');
module.exports = {
cooldown: 120,
data: new SlashCommandBuilder()
.setName('status')
.setDescription('Set the bot\'s status')
.addStringOption(option =>
option.setName('input')
.setDescription('The status to set')
.setMaxLength(128)
.setRequired(true)),
category: 'dev',
async execute(interaction) {
const status = interaction.options.getString('input');
const cancel = new ButtonBuilder()
.setCustomId('Cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary);
const playing = new ButtonBuilder()
.setCustomId('Playing')
.setLabel('Playing')
.setStyle(ButtonStyle.Primary);
const watching = new ButtonBuilder()
.setCustomId('Watching')
.setLabel('Watching')
.setStyle(ButtonStyle.Primary);
const listening = new ButtonBuilder()
.setCustomId('Listening')
.setLabel('Listening')
.setStyle(ButtonStyle.Primary);
const reset = new ButtonBuilder()
.setCustomId('Reset')
.setLabel('Reset')
.setStyle(ButtonStyle.Danger);
const row = new ActionRowBuilder()
.addComponents(cancel, playing, watching, listening, reset);
const content = `\`/status\` from ${interaction.user}`;
const type = interaction.customId;
const preType = new EmbedBuilder()
.setColor(0x2b2d31)
.setTitle('_No status type, moo?_ 🐄')
.setDescription(`**Status:** ${status}\n\nPlease pick a type for this status!`);
const selectType = EmbedBuilder.from(preType)
.setTitle('_Successful moo!_ 🐄')
.setDescription(`**Status:** ${status}\n**Type:** ${type}\n\nI have set the status!`)
.setFooter({ text: 'To set a different status, use /status again.' });
const resetType = EmbedBuilder.from(preType)
.setDescription('**Status:** reset\n\nI have reset the status!')
.setFooter({ text: 'To set another status, use /status again.' });
const response = await interaction.reply({
embeds: [preType], content: `${content}`, fetchReply: true,
components: [row],
});
const collectorFilter = i => i.user.id === interaction.user.id;
const selection = await response.awaitMessageComponent({ filter: collectorFilter });
if (selection.customId === 'Cancel') {
await response.suppressEmbeds();
await interaction.editReply({ content: '`/status` type selection cancelled.', components: [] });
}
else if (selection.customId === 'Reset') {
await interaction.client.user.setActivity(null);
await interaction.editReply({ embeds: [resetType], content: `${content}`, components: [] });
}
else if (selection.customId === 'Playing') {
await interaction.client.user.setActivity(`${status}`, { type: ActivityType.Playing });
await interaction.editReply({ embeds: [selectType], content: `${content}`, components: [] });
}
else if (selection.customId === 'Watching') {
await interaction.client.user.setActivity(`${status}`, { type: ActivityType.Watching });
await interaction.editReply({ embeds: [selectType], content: `${content}`, components: [] });
}
else if (selection.customId === 'Listening') {
await interaction.client.user.setActivity(`${status}`, { type: ActivityType.Listening });
await interaction.editReply({ embeds: [selectType], content: `${content}`, components: [] });
}
},
};
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { ActivityType } = require('discord.js');
module.exports = {
cooldown: 120,
data: new SlashCommandBuilder()
.setName('status')
.setDescription('Set the bot\'s status')
.addStringOption(option =>
option.setName('input')
.setDescription('The status to set')
.setMaxLength(128)
.setRequired(true)),
category: 'dev',
async execute(interaction) {
const status = interaction.options.getString('input');
const cancel = new ButtonBuilder()
.setCustomId('Cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary);
const playing = new ButtonBuilder()
.setCustomId('Playing')
.setLabel('Playing')
.setStyle(ButtonStyle.Primary);
const watching = new ButtonBuilder()
.setCustomId('Watching')
.setLabel('Watching')
.setStyle(ButtonStyle.Primary);
const listening = new ButtonBuilder()
.setCustomId('Listening')
.setLabel('Listening')
.setStyle(ButtonStyle.Primary);
const reset = new ButtonBuilder()
.setCustomId('Reset')
.setLabel('Reset')
.setStyle(ButtonStyle.Danger);
const row = new ActionRowBuilder()
.addComponents(cancel, playing, watching, listening, reset);
const content = `\`/status\` from ${interaction.user}`;
const type = interaction.customId;
const preType = new EmbedBuilder()
.setColor(0x2b2d31)
.setTitle('_No status type, moo?_ 🐄')
.setDescription(`**Status:** ${status}\n\nPlease pick a type for this status!`);
const selectType = EmbedBuilder.from(preType)
.setTitle('_Successful moo!_ 🐄')
.setDescription(`**Status:** ${status}\n**Type:** ${type}\n\nI have set the status!`)
.setFooter({ text: 'To set a different status, use /status again.' });
const resetType = EmbedBuilder.from(preType)
.setDescription('**Status:** reset\n\nI have reset the status!')
.setFooter({ text: 'To set another status, use /status again.' });
const response = await interaction.reply({
embeds: [preType], content: `${content}`, fetchReply: true,
components: [row],
});
const collectorFilter = i => i.user.id === interaction.user.id;
const selection = await response.awaitMessageComponent({ filter: collectorFilter });
if (selection.customId === 'Cancel') {
await response.suppressEmbeds();
await interaction.editReply({ content: '`/status` type selection cancelled.', components: [] });
}
else if (selection.customId === 'Reset') {
await interaction.client.user.setActivity(null);
await interaction.editReply({ embeds: [resetType], content: `${content}`, components: [] });
}
else if (selection.customId === 'Playing') {
await interaction.client.user.setActivity(`${status}`, { type: ActivityType.Playing });
await interaction.editReply({ embeds: [selectType], content: `${content}`, components: [] });
}
else if (selection.customId === 'Watching') {
await interaction.client.user.setActivity(`${status}`, { type: ActivityType.Watching });
await interaction.editReply({ embeds: [selectType], content: `${content}`, components: [] });
}
else if (selection.customId === 'Listening') {
await interaction.client.user.setActivity(`${status}`, { type: ActivityType.Listening });
await interaction.editReply({ embeds: [selectType], content: `${content}`, components: [] });
}
},
};
8 replies
DIAdiscord.js - Imagine a bot
•Created by beck on 7/28/2023 in #djs-questions
how to make this concept work?
i'm trying to make a command where i can set the bot's status & then choose the playing/watching/listening etc type in a select menu, & here is this attempt:
however every selection i make simply returns
const { ComponentType, ActivityType, ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('status')
.setDescription('Select a status for the bot')
.addStringOption(option =>
option.setName('status')
.setDescription('The status to set')
.setRequired(true)
.setMaxLength(128)),
async execute(interaction) {
const status = interaction.options.getString('status');
const select = new StringSelectMenuBuilder()
.setCustomId('type')
.setPlaceholder('Type of status')
.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel('Playing')
.setDescription('Playing /status')
.setValue('Playing'),
new StringSelectMenuOptionBuilder()
.setLabel('Watching')
.setDescription('Watching /status')
.setValue('Watching'),
new StringSelectMenuOptionBuilder()
.setLabel('Listening')
.setDescription('Listening to /status')
.setValue('Listening'),
);
const row = new ActionRowBuilder()
.addComponents(select);
const response = await interaction.reply({
content: 'Choose the type of status you want to set',
components: [row],
});
const collector = response.createMessageComponentCollector({ componentType: ComponentType.StringSelect, time: 3_600_000 });
collector.on('collect', async i => {
const selection = i.values[0].toLowerCase();
await interaction.client.user.setActivity(interaction.options.getString('status'), { type: ActivityType.select });
await i.reply(`${i.user} has set my status as ${selection} ${status}!`);
});
},
};
const { ComponentType, ActivityType, ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('status')
.setDescription('Select a status for the bot')
.addStringOption(option =>
option.setName('status')
.setDescription('The status to set')
.setRequired(true)
.setMaxLength(128)),
async execute(interaction) {
const status = interaction.options.getString('status');
const select = new StringSelectMenuBuilder()
.setCustomId('type')
.setPlaceholder('Type of status')
.addOptions(
new StringSelectMenuOptionBuilder()
.setLabel('Playing')
.setDescription('Playing /status')
.setValue('Playing'),
new StringSelectMenuOptionBuilder()
.setLabel('Watching')
.setDescription('Watching /status')
.setValue('Watching'),
new StringSelectMenuOptionBuilder()
.setLabel('Listening')
.setDescription('Listening to /status')
.setValue('Listening'),
);
const row = new ActionRowBuilder()
.addComponents(select);
const response = await interaction.reply({
content: 'Choose the type of status you want to set',
components: [row],
});
const collector = response.createMessageComponentCollector({ componentType: ComponentType.StringSelect, time: 3_600_000 });
collector.on('collect', async i => {
const selection = i.values[0].toLowerCase();
await interaction.client.user.setActivity(interaction.options.getString('status'), { type: ActivityType.select });
await i.reply(`${i.user} has set my status as ${selection} ${status}!`);
});
},
};
ActivityType.Playing
despite me trying to make the Playing
give whichever value, i'm pretty sure i missed something but i can't really figure out what. no worries if no help is able to be given, but i feel like there's probably an easy fix or i overlooked something?22 replies