Чтобы отправить сообщение на определенный канал с помощью discord.js, вы можете использовать следующие методы:
-
Использование идентификатора канала:
const Discord = require('discord.js'); const client = new Discord.Client(); client.on('ready', () => { const channel = client.channels.cache.get('CHANNEL_ID'); // Replace CHANNEL_ID with the actual channel ID if (channel) { channel.send('Hello, channel!'); } }); client.login('YOUR_BOT_TOKEN'); -
Использование названия канала:
const Discord = require('discord.js'); const client = new Discord.Client(); client.on('ready', () => { const guild = client.guilds.cache.get('GUILD_ID'); // Replace GUILD_ID with the actual guild (server) ID if (guild) { const channel = guild.channels.cache.find(ch => ch.name === 'channel-name'); // Replace 'channel-name' with the actual channel name if (channel) { channel.send('Hello, channel!'); } } }); client.login('YOUR_BOT_TOKEN'); -
Использование упоминания канала:
const Discord = require('discord.js'); const client = new Discord.Client(); client.on('ready', () => { const channel = client.channels.cache.get('CHANNEL_ID'); // Replace CHANNEL_ID with the actual channel ID if (channel) { channel.send('Hello, <#CHANNEL_ID>!'); // Replace CHANNEL_ID with the actual channel ID } }); client.login('YOUR_BOT_TOKEN'); -
Использование объекта канала:
const Discord = require('discord.js'); const client = new Discord.Client(); client.on('ready', () => { const channel = client.channels.cache.get('CHANNEL_ID'); // Replace CHANNEL_ID with the actual channel ID if (channel) { channel.send('Hello, channel!'); } }); client.login('YOUR_BOT_TOKEN');
Для всех методов обязательно замените 'YOUR_BOT_TOKEN'на токен вашего бота, 'CHANNEL_ID'на желаемый идентификатор канала, 'GUILD_ID'с идентификатором гильдии (сервера) и 'channel-name'с именем канала, на который вы хотите отправить сообщение.