При попытке создать реакцию от бота на слеш команду вылетает ошибка (Discord)

Содержание ошибки:

(node:4540) UnhandledPromiseRejectionWarning: Error: Request failed with status code 400
at createError (D:\bot\node_modules\axios\lib\core\createError.js:16:15)
at settle (D:\bot\node_modules\axios\lib\core\settle.js:17:12)
at IncomingMessage.handleStreamEnd (D:\bot\node_modules\axios\lib\adapters\http.js:260:11)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4540) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:4540) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Код бота:

const Discord = require('discord.js');
const client = new Discord.Client();
const axios = require('axios');
var token = "tytesttoken";

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});
client.on('raw', async e => {
    if(e.t === "INTERACTION_CREATE"){
        const url = "https://discord.com/api/v8/interactions/${e.d.id}/${e.d.token}/callback"
        const body = {
            "type": 4,
            "data": {
                "content": "Hewwo)"
            }
        }
        const data = await axios.post(url, body, null);
        console.log(data) 
    }
});

client.login(token);

У зарубежного чела все работает


Ответы (1 шт):

Автор решения: Cipher

Вы пытаетесь вставить переменную {e.d.token} в строку, вместо строкового выражения. Вам нужно заменить:

"https://discord.com/api/v8/interactions/${e.d.id}/${e.d.token}/callback"

На

`https://discord.com/api/v8/interactions/${e.d.id}/${e.d.token}/callback`

Я бы рекомендовал использовать методы библиотеки, неже ли прямые запросы к API.

→ Ссылка