Здравствуйте. Я пытаюсь сделать, чтобы бот написал в чат по ID. Пишу данный код:
client.channels.fetch('1007311557300068432')
.then(channel => channel.send('ok'))
Но получаю ошибку, которая указана в заголовке. Бот на сервере, на котором этот канал, есть. Что делать?
UPD:
const {SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, GatewayIntentBits, EmbedBuilder} = require('discord.js')
const client = new Client({intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildPresences]});
module.exports = {
data: new SlashCommandBuilder()
.setName('add-animal')
.setNameLocalizations({"ru": "добавить-животное"})
.setDescription('Add animals to game "Guess the animal"!')
.setDescriptionLocalizations({"ru": 'Добавь животное в игру "Угадай животное"!'})
.addStringOption(option =>
option.setName('name')
.setNameLocalizations({"ru": 'имя'})
.setDescription("Animal name")
.setDescriptionLocalizations({"ru": "Имя животного"})
.setRequired(true)
)
.addAttachmentOption(option =>
option.setName('image')
.setNameLocalizations({"ru": "изображение"})
.setDescription("Animal image")
.setDescriptionLocalizations({"ru": "Изображение животного"})
.setRequired(true)
),
async execute(interaction) {
const name = interaction.options.getString('name')
const image = interaction.options.getAttachment('image')
const embed = new EmbedBuilder()
.setTitle(name)
.setDescription(`Прислал: ${interaction.user}`)
.setImage(image.url)
client.channels.fetch('1007311557300068432')
.then(channel => channel.send('ok'))
interaction.reply("ок")
}
}
Ошибка:
Error: Expected token to be set for this request, but none was present
at _RequestManager.resolveRequest (/home/nikita/apkdownloaderbot/node_modules/@discordjs/rest/dist/lib/RequestManager.cjs:142:15)
at _RequestManager.queueRequest (/home/nikita/apkdownloaderbot/node_modules/@discordjs/rest/dist/lib/RequestManager.cjs:115:46)
at REST.raw (/home/nikita/apkdownloaderbot/node_modules/@discordjs/rest/dist/lib/REST.cjs:56:32)
at REST.request (/home/nikita/apkdownloaderbot/node_modules/@discordjs/rest/dist/lib/REST.cjs:52:33)
at REST.get (/home/nikita/apkdownloaderbot/node_modules/@discordjs/rest/dist/lib/REST.cjs:37:17)
at ChannelManager.fetch (/home/nikita/apkdownloaderbot/node_modules/discord.js/src/managers/ChannelManager.js:123:41)
at Object.execute (/home/nikita/apkdownloaderbot/commands/add-animal.js:30:25)
at Client.<anonymous> (/home/nikita/apkdownloaderbot/index.js:41:23)
at Client.emit (node:events:513:28)
at InteractionCreateAction.handle (/home/nikita/apkdownloaderbot/node_modules/discord.js/src/client/actions/InteractionCreate.js:81:12)