❄Moba Welt❄
❄Moba Welt❄
DIAdiscord.js - Imagine an app
Created by ❄Moba Welt❄ on 4/1/2024 in #djs-questions
Send Embed to Channel with ID
I would like to send my embed to a channel specified by ID. Unfortunately it doesn't work in my code.
const { EmbedBuilder, ButtonInteraction } = require("discord.js");

module.exports = {
name: "interactionCreate",
once: false,
/**
*
* @param {ButtonInteraction} interaction
* @param {*} client
*/
async execute(interaction, client) {
if(interaction.isButton()) {
if(interaction.customId == "einstempeln") {
const channel = client.channels.cache.get('1222955254174453945');
if (!channel) return console.log("Channel not found");

const embed = new EmbedBuilder()
.setColor(0x6AA84F)
.setTitle('Dienst-Eintragung')
.setDescription('Du hast dich erfolgreich in den Dienst eingetragen!')
.setTimestamp()
.setFooter({text: 'Benni Techniker'});

channel.send({embeds: [embed]});
}
}
}
}
const { EmbedBuilder, ButtonInteraction } = require("discord.js");

module.exports = {
name: "interactionCreate",
once: false,
/**
*
* @param {ButtonInteraction} interaction
* @param {*} client
*/
async execute(interaction, client) {
if(interaction.isButton()) {
if(interaction.customId == "einstempeln") {
const channel = client.channels.cache.get('1222955254174453945');
if (!channel) return console.log("Channel not found");

const embed = new EmbedBuilder()
.setColor(0x6AA84F)
.setTitle('Dienst-Eintragung')
.setDescription('Du hast dich erfolgreich in den Dienst eingetragen!')
.setTimestamp()
.setFooter({text: 'Benni Techniker'});

channel.send({embeds: [embed]});
}
}
}
}
17 replies
DIAdiscord.js - Imagine an app
Created by ❄Moba Welt❄ on 3/29/2024 in #djs-questions
client.on Error
Hello. The first Code block are my Code and the Second is the Error.
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } = require('discord.js');
const { Client } = require('discord.js');
const client = require('../../../index.js').client;
// Replace 'YOUR_CHANNEL_ID_HERE' with the actual channel ID
const CHANNEL_ID = '1222955254174453945';
const exampleEmbed = new EmbedBuilder()
.setTitle('Stempeluhr')
.setThumbnail('https://cdn.pixabay.com/photo/2016/08/19/20/37/time-1606153_1280.png')
.setDescription(`Sie haben sich erfolgreich eingestempelt: <t:${Date.now()}:R>`);

client.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
if (interaction.message.id !== interaction.message.id) return;
if (interaction.customId === 'einstempeln') {
const channel = client.channels.cache.get(CHANNEL_ID);

if (channel) {
await channel.send({ embeds: [exampleEmbed] });
interaction.message.edit({ components: [] });
interaction.reply({ content: 'Sie haben sich erfolgreich eingestempelt!', ephemeral: true });
} else {
// Handle the case where the channel is not found
console.log(`Channel with ID ${CHANNEL_ID} not found`);
}
}
});
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } = require('discord.js');
const { Client } = require('discord.js');
const client = require('../../../index.js').client;
// Replace 'YOUR_CHANNEL_ID_HERE' with the actual channel ID
const CHANNEL_ID = '1222955254174453945';
const exampleEmbed = new EmbedBuilder()
.setTitle('Stempeluhr')
.setThumbnail('https://cdn.pixabay.com/photo/2016/08/19/20/37/time-1606153_1280.png')
.setDescription(`Sie haben sich erfolgreich eingestempelt: <t:${Date.now()}:R>`);

client.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
if (interaction.message.id !== interaction.message.id) return;
if (interaction.customId === 'einstempeln') {
const channel = client.channels.cache.get(CHANNEL_ID);

if (channel) {
await channel.send({ embeds: [exampleEmbed] });
interaction.message.edit({ components: [] });
interaction.reply({ content: 'Sie haben sich erfolgreich eingestempelt!', ephemeral: true });
} else {
// Handle the case where the channel is not found
console.log(`Channel with ID ${CHANNEL_ID} not found`);
}
}
});
6 replies