Zarchical
Zarchical
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by Zarchical on 7/31/2023 in #djs-questions
How do I send a message in a seperate channel from a slash command?
I've been trying to do this but can't seem to figure out how to get the client into the slash command. Any help would be greatly appreciated. Below is a snippet of my imports and some code which is trying to send the message, however failing because client is undefined. Imports:
const { EmbedBuilder, SlashCommandBuilder, ButtonStyle, ButtonBuilder } = require('discord.js');
const path = require('path');
const config = require(path.join(__dirname, '..', '..', 'configuration.json'));
const { EmbedBuilder, SlashCommandBuilder, ButtonStyle, ButtonBuilder } = require('discord.js');
const path = require('path');
const config = require(path.join(__dirname, '..', '..', 'configuration.json'));
Code:
const channelID = '1135231042287042561';
const channel = client.channels.cache.get(channelID);

if (channel && channel.isText()) {
const exampleEmbed = new EmbedBuilder()
.setColor('5865F2')
.setTitle("New Script")
.setDescription(`A new script has been posted by <@${interaction.user.id}>!`)
.addFields(
{"name": "Script URL", "value": "[Open the script here](https://raw.githubusercontent.com/" + DataURL + ")", "inline": true,},
{"name": "Script Name", "value": data.name, "inline": true,},
{"name": "Script ID", "value": random})
const confirm = new ButtonBuilder()
.setCustomId('delete')
.setLabel('Delete Script')
.setStyle(ButtonStyle.Danger);

const row = new MessageActionRow()
.addComponents(confirm)

channel.send({ embeds: [exampleEmbed], components: [row] })
.then(() => console.log('Message sent with the "delete" button!'))
.catch(console.error);
}
const channelID = '1135231042287042561';
const channel = client.channels.cache.get(channelID);

if (channel && channel.isText()) {
const exampleEmbed = new EmbedBuilder()
.setColor('5865F2')
.setTitle("New Script")
.setDescription(`A new script has been posted by <@${interaction.user.id}>!`)
.addFields(
{"name": "Script URL", "value": "[Open the script here](https://raw.githubusercontent.com/" + DataURL + ")", "inline": true,},
{"name": "Script Name", "value": data.name, "inline": true,},
{"name": "Script ID", "value": random})
const confirm = new ButtonBuilder()
.setCustomId('delete')
.setLabel('Delete Script')
.setStyle(ButtonStyle.Danger);

const row = new MessageActionRow()
.addComponents(confirm)

channel.send({ embeds: [exampleEmbed], components: [row] })
.then(() => console.log('Message sent with the "delete" button!'))
.catch(console.error);
}
3 replies