skeddles
skeddles
DIAdiscord.js - Imagine an app
Created by skeddles on 6/18/2024 in #djs-questions
Why is my number of emoji inaccurate?
No description
9 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 1/23/2024 in #djs-questions
Command Wont Go Away
For some reason my command was listed twice in the command list. So I deleted the command from my bot, then restarted it. Now one of them was deleted, but the other is still there. How can I delete the command?
6 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 1/21/2024 in #djs-questions
Why isn't messageCreate getting triggered?
import { Client, GatewayIntentBits, Partials } from 'discord.js';
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});


client.once('ready', async c => {
console.log('bot is logged in');
});

client.on('messageCreate', async message => {
console.log('message received:', message.content);
});

client.login(process.env.DISCORD_BOT_TOKEN);

export default client;
import { Client, GatewayIntentBits, Partials } from 'discord.js';
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});


client.once('ready', async c => {
console.log('bot is logged in');
});

client.on('messageCreate', async message => {
console.log('message received:', message.content);
});

client.login(process.env.DISCORD_BOT_TOKEN);

export default client;
the on ready is getting logged, but when i send messages, there's no response. why not?
8 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 11/8/2023 in #djs-questions
Why does my entire app crash when client.login fails?
try { client.login(process.env.DISCORD_BOT_TOKEN); } catch (err) { console.error('failed to login to discordfailed to login to discord', err); reject(err); } trying to login to discord through my website. If the client.login fails (because discord reset my token for the 10th time), then the entire website crashes. I'm trying to catch the error, but it doesn't catch it, it just crashes the whole app. how do i avoid that? djs 14.7.1
5 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 11/8/2023 in #djs-questions
why does this work in dev but not production
client.guilds.cache.get(CONFIG.guildId).channels.cache.get(CONFIG.siteLogChannelId).send('Bot started');
client.guilds.cache.get(CONFIG.guildId).channels.cache.get(CONFIG.siteLogChannelId).send('Bot started');
on my dev environment it works fine. then I deploy it, and it crashes the whole site because .channels is undefined.
5 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 10/30/2023 in #djs-questions
using rest API to update server banner
I'm trying to use the REST api to update my server banner. The problem is that it seems to work - the await rest.patch() line does not throw an error, and it returns the guild object (which I believe it so be expected upon success). But when I look at my server, the banner is unchanged. I thought it might be cached, but I did a hard refresh on the website, and also waiting 12 hours. What am I doing wrong?
//import .env variables
import dotenv from 'dotenv';
dotenv.config();
import promises from 'fs/promises';
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';
import { glob } from 'glob';


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

(async () => {
try {

//get guild data
let guild = await rest.get(Routes.guild(process.env.DISCORD_GUILD_ID));
console.log('Got guild "'+ guild.name +'"');
let guildHasBanner = guild.features.includes('BANNER');
console.log('Guild has banner: ', guildHasBanner, guild.banner);
if (!guildHasBanner) throw 'Guild does not have access to banner feature';

//get banner
let listOfBannerFiles = await glob('_banners/*.png');
let randomBannerFile = listOfBannerFiles[Math.floor(Math.random() * listOfBannerFiles.length)];
console.log('setting banner to: ', randomBannerFile);
let imageData = await loadImage(randomBannerFile);

//update banner
await rest.patch(Routes.guild(process.env.DISCORD_GUILD_ID), {data: {banner: imageData}});
console.log('Banner updated successfully!');
} catch (error) {
console.error(error);
}
})();
//import .env variables
import dotenv from 'dotenv';
dotenv.config();
import promises from 'fs/promises';
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';
import { glob } from 'glob';


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

(async () => {
try {

//get guild data
let guild = await rest.get(Routes.guild(process.env.DISCORD_GUILD_ID));
console.log('Got guild "'+ guild.name +'"');
let guildHasBanner = guild.features.includes('BANNER');
console.log('Guild has banner: ', guildHasBanner, guild.banner);
if (!guildHasBanner) throw 'Guild does not have access to banner feature';

//get banner
let listOfBannerFiles = await glob('_banners/*.png');
let randomBannerFile = listOfBannerFiles[Math.floor(Math.random() * listOfBannerFiles.length)];
console.log('setting banner to: ', randomBannerFile);
let imageData = await loadImage(randomBannerFile);

//update banner
await rest.patch(Routes.guild(process.env.DISCORD_GUILD_ID), {data: {banner: imageData}});
console.log('Banner updated successfully!');
} catch (error) {
console.error(error);
}
})();
6 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 9/18/2023 in #djs-questions
Response: 500 Internal Server Error when bot tries to post a message
Recently my bot has had issues occasionally when posting an automated message to certain threads. Is this a discord problem or a me problem? It says 500 error, so it seems like a discord problem, but who knows.
3 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 9/6/2023 in #djs-questions
Missing Access Error
No description
8 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 8/7/2023 in #djs-questions
delete bot messages
11 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 4/21/2023 in #djs-questions
DiscordAPIError[50035]: Invalid Form Bodydata[BASE_TYPE_REQUIRED]: This field is required
DiscordAPIError[50035]: Invalid Form Body
data[BASE_TYPE_REQUIRED]: This field is required
DiscordAPIError[50035]: Invalid Form Body
data[BASE_TYPE_REQUIRED]: This field is required
trying to show a modal
function popupModal (messageId) {
const popupModal = new ModalBuilder()
.setCustomId('edit-message-'+messageId)
.setTitle('Edit A Bot Message');

const newMessageInput = new TextInputBuilder()
.setCustomId('newMessage')
.setLabel("Enter the new message to replace the old one.")
.setStyle(TextInputStyle.Paragraph);

const firstActionRow = new ActionRowBuilder().addComponents(newMessageInput);
popupModal.addComponents(firstActionRow);
}

await interaction.showModal(popupModal(interaction.targetId));
function popupModal (messageId) {
const popupModal = new ModalBuilder()
.setCustomId('edit-message-'+messageId)
.setTitle('Edit A Bot Message');

const newMessageInput = new TextInputBuilder()
.setCustomId('newMessage')
.setLabel("Enter the new message to replace the old one.")
.setStyle(TextInputStyle.Paragraph);

const firstActionRow = new ActionRowBuilder().addComponents(newMessageInput);
popupModal.addComponents(firstActionRow);
}

await interaction.showModal(popupModal(interaction.targetId));
what does this mean? what field and I missing?
4 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 4/1/2023 in #djs-questions
Permission to add role?
15 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 4/1/2023 in #djs-questions
Where can I find the options for creating a thread?
this guide page https://discordjs.guide/popular-topics/threads.html#thread-related-gateway-events has
const thread = await channel.threads.create({
name: 'food-talk',
autoArchiveDuration: 60,
reason: 'Needed a separate thread for food',
});
const thread = await channel.threads.create({
name: 'food-talk',
autoArchiveDuration: 60,
reason: 'Needed a separate thread for food',
});
When i look up this method: https://discord.js.org/#/docs/discord.js/14.8.0/class/GuildTextThreadManager?scrollTo=create then click "thread create options", it brings me to this page: https://discord.js.org/#/docs/discord.js/14.8.0/typedef/ThreadCreateOptions but this only lists "startMessage", "type", "invitable" Where are the other options? Where am I supposed to look? What did I do wrong?
5 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 3/30/2023 in #djs-questions
how do you get access to your instantiated `discordjs.Client` from imported files?
I can't do export client and import my main file, because that would create a circular dependency. how is it usually done? should i just make client global / attach it to process?
13 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 2/28/2023 in #djs-questions
How do I check if a messages user has a specific role?
let channel = client.channels.cache.get(DISCORD_COLLABS_CHANNEL);
let messages = await channel.messages.fetch({limit: 100, cache: false});
console.log (' here is the first message', Array.from(messages)[0]);
let lastPostByAdmin = Array.from(messages).filter(m=>m[1].member.roles.cache.has(DISCORD_ADMIN_ROLE));
let channel = client.channels.cache.get(DISCORD_COLLABS_CHANNEL);
let messages = await channel.messages.fetch({limit: 100, cache: false});
console.log (' here is the first message', Array.from(messages)[0]);
let lastPostByAdmin = Array.from(messages).filter(m=>m[1].member.roles.cache.has(DISCORD_ADMIN_ROLE));
it doesn't like the last line, cant find .member (but on the docs it says messages have a member property containing the guild member?) I can do user, but it doesn't look like that lets you fetch the roles, just has the basic info.
9 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 2/24/2023 in #djs-voice
get screenshots of streams?
is it possible to get screenshots of current streams? or even better, to stream their video elsewhere?
5 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 1/30/2023 in #djs-questions
fetch video stream
can i get a video stream? either to get a screenshot of what it is or the whole video stream, to then save to a file or stream elsewhere?
2 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 11/29/2022 in #djs-voice
get volume
i cant find the place in the docs that talks about volume, ive seen code like volume.setVolume(0.2); but cant find setVolume. https://discord.js.org/#/docs/voice/main/class/AudioResource?scrollTo=volume this page talks about volume, but not any of its submethods or anything, no link
4 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 11/3/2022 in #djs-voice
dynamic volume levelling
i made a bot that plays music in a VC from mp3 files. unfortunately their volumes are all over the place. has anyone made it so their bot adjusts the volume automatically so they're all the same?
3 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 11/3/2022 in #djs-questions
dynamic volume levelling
i made a bot that plays music in a VC from mp3 files. unfortunately their volumes are all over the place. has anyone made it so their bot adjusts the volume automatically so they're all the same?
4 replies
DIAdiscord.js - Imagine an app
Created by skeddles on 10/30/2022 in #djs-questions
how should i get user data with multiple inputs
how would you format a user input where the user might need to enter some of the values multiple times (and be grouped together)? ie a command that adds an enemy to a game, and you want to configure the list of items it will drop, where each item needs a name, and how often it should drop ideally in a single command
6 replies