const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', message => {
if (message.channel.id === 'YOUR_CHANNEL_ID' && message.attachments.size > 0) {
const attachment = message.attachments.first();
const messageContainer = document.getElementById('message-container');
messageContainer.innerHTML += `
<div class="message">
<div class="author">
<img src="${message.author.displayAvatarURL()}" alt="Author avatar">
</div>
<div>
<p><strong>Autor:</strong> ${message.author.username}</p>
<p>${message.content}</p>
<img src="${attachment.url}" alt="Image">
${message.attachments.size > 1 ? `<p><strong>Archivo:</strong> ${message.attachments.array()[1].url}</p>` : ''}
</div>
</div>
`;
}
});
client.login('YOUR_DISCORD_BOT_TOKEN');
Welcome to the community, @HypnoStudios!
Could you describe the problem in more detail? A link to the Repl can also help us view the issue more in depth.
2 Likes
You seem to using frontend-js and backend-js in the same file, unless you are connecting them some other way this should not work, as “document” does not exist on node.
You can’t make a discord bot in a website like this, but you could make some API routes on a node.js webserver which returns the information needed, and use fetch
on the client side JS. For this I would recommend
1 Like