Amir
Amir
DIAdiscord.js - Imagine a bot
Created by Amir on 6/7/2024 in #djs-questions
How do I know which gateway intents I need for a certain event in Discord.js?
How do I know which gateway intents I need for a certain event in Discord.js? For instance, if I want my bot to respond to the "messageCreate" event, how can I find out which gateway intents are necessary?
10 replies
DIAdiscord.js - Imagine a bot
Created by Amir on 6/5/2024 in #djs-questions
Simplifying the API request process
import { REST } from '@discordjs/rest';
import { API } from '@discordjs/core/http-only';

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

await api.channels.createMessage('channelId', { content: 'Hello World' });
import { REST } from '@discordjs/rest';
import { API } from '@discordjs/core/http-only';

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

await api.channels.createMessage('channelId', { content: 'Hello World' });
This code works well, but can we streamline it further? Currently, we specify the channelId separately from the request body. Is there a way to combine all required parameters into one object, like this?
await api.channels.createMessage({ channelId, 'xxxxxxxx', content: 'Hello World' });
await api.channels.createMessage({ channelId, 'xxxxxxxx', content: 'Hello World' });
19 replies
DIAdiscord.js - Imagine a bot
Created by Amir on 6/5/2024 in #djs-questions
Simplifying API Requests
Here's the code I'm using:
import { REST, Routes } from 'discord.js';

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

rest.request({
fullRoute: Routes.channelMessages('xxxxxxxxxx'),
method: 'POST',
body: {
content: 'test'
}
});
import { REST, Routes } from 'discord.js';

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

rest.request({
fullRoute: Routes.channelMessages('xxxxxxxxxx'),
method: 'POST',
body: {
content: 'test'
}
});
It works well, but I have one question: Is there a way to send requests without specifying the method? I'd like to just send requests to the endpoint without specifying the method each time.
9 replies