sproj003 ♿
sproj003 ♿
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 5/16/2024 in #djs-questions
React to message with emoji
I know it's probably something really simple but my bot sends a message not in response to an interaction. It should then react to that message with random emojis.
const channel = client.channels.cache.get("1239901826221080637");
const checkinOptions = {
"FoodEmojis": [
":canned_food:",
":pie:",
":rice:",
":spaghetti:",
":stew:",
":meat_on_bone:",
":cut_of_meat:",
":croissant:",
":pretzel:",
":french_bread:",
":bread:",
":salad:",
":sandwich:",
":poultry_leg:",
":hamburger:",
":pizza:",
":ramen:",
":curry:",
],
"DrinksEmojis": [
":tropical_drink:",
":beverage_box:",
":bubble_tea:",
":cup_with_straw:",
":milk:",
":tea:",
":coffee:",
],
"ToiletEmojis": [
":toilet:",
":poop:"
],
"PetsEmojis": [
":cat2:",
":dog2:",
":fish:",
":bird:",
":parrot:",
":snake:",
":hamster:",
":mouse2:",
]
};

const emojiFood = checkinOptions.FoodEmojis[Math.floor(Math.random() * checkinOptions.FoodEmojis.length)];
const emojiDrinks = checkinOptions.DrinksEmojis[Math.floor(Math.random() * checkinOptions.DrinksEmojis.length)];
const emojiPets = checkinOptions.PetsEmojis[Math.floor(Math.random() * checkinOptions.PetsEmojis.length)];

messageSend.content = "Complete this check in today";
messageSend.embeds = [
new EmbedBuilder()
.setTitle(`${checkinOptions.Title[Math.floor(Math.random() * checkinOptions.Title.length)]}`)
.setDescription(`Make sure you get these things done by the end of the day.\n\nFood: ${emojiFood}\nDrinks: ${emojiDrinks}\nPets: ${emojiPets}`)
.setColor('#00FBDC')
];
messageSend.fetchReply = true;

const message = await channel.send(messageSend);
await message.react(`${emojiFood}`);
await message.react(`${emojiDrinks}`);
await message.react(`${emojiPets}`);
const channel = client.channels.cache.get("1239901826221080637");
const checkinOptions = {
"FoodEmojis": [
":canned_food:",
":pie:",
":rice:",
":spaghetti:",
":stew:",
":meat_on_bone:",
":cut_of_meat:",
":croissant:",
":pretzel:",
":french_bread:",
":bread:",
":salad:",
":sandwich:",
":poultry_leg:",
":hamburger:",
":pizza:",
":ramen:",
":curry:",
],
"DrinksEmojis": [
":tropical_drink:",
":beverage_box:",
":bubble_tea:",
":cup_with_straw:",
":milk:",
":tea:",
":coffee:",
],
"ToiletEmojis": [
":toilet:",
":poop:"
],
"PetsEmojis": [
":cat2:",
":dog2:",
":fish:",
":bird:",
":parrot:",
":snake:",
":hamster:",
":mouse2:",
]
};

const emojiFood = checkinOptions.FoodEmojis[Math.floor(Math.random() * checkinOptions.FoodEmojis.length)];
const emojiDrinks = checkinOptions.DrinksEmojis[Math.floor(Math.random() * checkinOptions.DrinksEmojis.length)];
const emojiPets = checkinOptions.PetsEmojis[Math.floor(Math.random() * checkinOptions.PetsEmojis.length)];

messageSend.content = "Complete this check in today";
messageSend.embeds = [
new EmbedBuilder()
.setTitle(`${checkinOptions.Title[Math.floor(Math.random() * checkinOptions.Title.length)]}`)
.setDescription(`Make sure you get these things done by the end of the day.\n\nFood: ${emojiFood}\nDrinks: ${emojiDrinks}\nPets: ${emojiPets}`)
.setColor('#00FBDC')
];
messageSend.fetchReply = true;

const message = await channel.send(messageSend);
await message.react(`${emojiFood}`);
await message.react(`${emojiDrinks}`);
await message.react(`${emojiPets}`);
What am I missing?
9 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 5/7/2024 in #djs-questions
Bot permission in channel
I'm trying to get my bot to check if it has permissions to send a message in a channel. It will mainly be for text channels but also in forum posts and voice channels. Not sure what I'm doing wrong. I'm getting the IDs for the guild and channel from a database.
const guild = client.guilds.cache.get(result[i].Guild);
...
const channel = guild.channels.fetch(result[i].ChannelID);
const channel = guild.channels.fetch(result[i].ChannelID);
if (channel) {
// Check permissions
if (!channel.permissionsFor(guild.members.me).has(PermissionFlagsBits.SendMessages)) {
logger.error(`Unable to post Queued Message ${result[i].QueuedMsgID} - Bot does not have permission to send messages in ${channel.name} in ${guild.name}`);
return;
}
const guild = client.guilds.cache.get(result[i].Guild);
...
const channel = guild.channels.fetch(result[i].ChannelID);
const channel = guild.channels.fetch(result[i].ChannelID);
if (channel) {
// Check permissions
if (!channel.permissionsFor(guild.members.me).has(PermissionFlagsBits.SendMessages)) {
logger.error(`Unable to post Queued Message ${result[i].QueuedMsgID} - Bot does not have permission to send messages in ${channel.name} in ${guild.name}`);
return;
}
6 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 1/17/2024 in #djs-questions
get application commands
As part of the js file that registers my commands, I want to get the existing commands before registering the new one. This is for both global and guild commands. There is no connection to the client in this file and I'm using @discordjs/rest.
const { Routes } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('@discordjs/rest');
const token = process.env.DISCORD_TOKEN;
const clientId = process.env.clientId;
const guildId = process.env.devGuildId;

const rest = new REST({ version: '10' }).setToken(token);

let curCommands, curDevCommands, newCommands, newDevCommands, commandsPath, commandFiles, file, command;

newCommands = newDevCommands = curCommands = curDevCommands = [];


// for global commands

// get current commands
rest.get(Routes.applicationCommands(clientId))
.then(() =>
// Not sure what goes here
)
.catch(logger.error);
curCommands =

commandsPath = path.join(__dirname, './commands');
commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js') && !file.startsWith('._'));

for (file of commandFiles) {
command = require(`./commands/${file}`);
newCommands.push(command.data.toJSON());
}

logger.debug("Global commands:" + newCommands);
rest.put(Routes.applicationCommands(clientId), { body: newCommands })
.then(() => logger.info('Successfully registered ' + newCommands.length + ' global commands.'))
.catch(logger.error);

for (let commandi of newCommands) {
console.group(commandi.name);
console.log(commandi.description);
if (commandi.options) {
for (let option of commandi.options) {
console.log(option.name + ": " + option.description);
}
}
console.groupEnd();
}

// SAME FOR Guild Commands
const { Routes } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('@discordjs/rest');
const token = process.env.DISCORD_TOKEN;
const clientId = process.env.clientId;
const guildId = process.env.devGuildId;

const rest = new REST({ version: '10' }).setToken(token);

let curCommands, curDevCommands, newCommands, newDevCommands, commandsPath, commandFiles, file, command;

newCommands = newDevCommands = curCommands = curDevCommands = [];


// for global commands

// get current commands
rest.get(Routes.applicationCommands(clientId))
.then(() =>
// Not sure what goes here
)
.catch(logger.error);
curCommands =

commandsPath = path.join(__dirname, './commands');
commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js') && !file.startsWith('._'));

for (file of commandFiles) {
command = require(`./commands/${file}`);
newCommands.push(command.data.toJSON());
}

logger.debug("Global commands:" + newCommands);
rest.put(Routes.applicationCommands(clientId), { body: newCommands })
.then(() => logger.info('Successfully registered ' + newCommands.length + ' global commands.'))
.catch(logger.error);

for (let commandi of newCommands) {
console.group(commandi.name);
console.log(commandi.description);
if (commandi.options) {
for (let option of commandi.options) {
console.log(option.name + ": " + option.description);
}
}
console.groupEnd();
}

// SAME FOR Guild Commands
11 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 12/6/2023 in #djs-questions
View Guild Onboarding
No description
7 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 11/22/2023 in #djs-questions
Set GuildScheduledEvent image
What's the easiest way for me to add/change the cover image of a Guild Event?
4 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 11/8/2023 in #djs-questions
SelectMenuBuilder Union Types
I'm attempting to send a SelectMenu in a message but I'm getting this error
Unhandled promise rejection: Invalid Form Body\ndata.components[0].components[0][UNION_TYPE_CHOICES]: Value of field \"type\" must be one of (2, 3, 5, 6, 7, 8).\ndata.components[1].components[0][UNION_TYPE_CHOICES]: Value of field \"type\" must be one of (2, 3, 5, 6, 7, 8).
Unhandled promise rejection: Invalid Form Body\ndata.components[0].components[0][UNION_TYPE_CHOICES]: Value of field \"type\" must be one of (2, 3, 5, 6, 7, 8).\ndata.components[1].components[0][UNION_TYPE_CHOICES]: Value of field \"type\" must be one of (2, 3, 5, 6, 7, 8).
My code is in the attachment When I remove the SelectMenus, it works fine
14 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 8/24/2023 in #djs-questions
Slash command channel types
Is it possible for me to filter out channels that are shown in the options by type. Here's my code:
.addChannelOption(option => option
.setName('channel')
.setDescription('The channel to send the embed to')
.setRequired(true)
)
.addChannelOption(option => option
.setName('channel')
.setDescription('The channel to send the embed to')
.setRequired(true)
)
Is it possible for me to filter the channels shown to just channel types text channels and voice channels but not forum channels?
8 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 5/5/2023 in #djs-questions
Not enough sessions
I got this error when starting my bot
Error: Not enough sessions remaining to spawn 1 shards; only 0 remaining; resets at 2023-05-05T16:50:40.537Z
| at WebSocketManager.connect (/Blazing Bots/campmaster-bot/node_modules/@discordjs/ws/dist/index.js:1362:13)
| at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
| at async WebSocketManager.connect (/Blazing Bots/campmaster-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:206:5)
at async Client.login (/Blazing Bots/campmaster-bot/node_modules/discord.js/src/client/Client.js:226:7)
Error: Not enough sessions remaining to spawn 1 shards; only 0 remaining; resets at 2023-05-05T16:50:40.537Z
| at WebSocketManager.connect (/Blazing Bots/campmaster-bot/node_modules/@discordjs/ws/dist/index.js:1362:13)
| at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
| at async WebSocketManager.connect (/Blazing Bots/campmaster-bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:206:5)
at async Client.login (/Blazing Bots/campmaster-bot/node_modules/discord.js/src/client/Client.js:226:7)
What does this mean?
4 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 2/22/2023 in #djs-questions
Voice channel reactions
Is there a way for me to detect when a user uses reactions in a voice channel. Not the chat in the voice channel. Some kind of event?
5 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 2/21/2023 in #djs-questions
slash command string limit
Is there a limit to how many characters I can put in a slash command string option?
5 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 1/16/2023 in #djs-questions
use other bot slash commands
When I set up the application on Discord, I was able to let it use other bot's slash commands. How do I use this in Discord.JS?
8 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 1/10/2023 in #djs-questions
autocomplete not working
Autocomplete won't show in discord
12 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 11/7/2022 in #djs-questions
Get all users who have a role
I'm trying to get a list of User IDs for everyone in a server who has a particular role. Here is my code.
memberIds = message.guild.roles.cache.get(camps.CodeCamp.Roles.Bootcamper).members.map(m => m.user.id);
memberIds = message.guild.roles.cache.get(camps.CodeCamp.Roles.Bootcamper).members.map(m => m.user.id);
Camps is a json file
58 replies
DIdiscord.js - Imagine ❄
Created by sproj003 ♿ on 10/11/2022 in #djs-questions
Message ID of first message in channel
I want the message ID of the first message in a channel to use as a link as a bookmark. Is this possible?
5 replies