Skip to content

Instantly share code, notes, and snippets.

@gdscbot
Created February 23, 2023 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdscbot/bf0d416b7651655ff49c8a922c002503 to your computer and use it in GitHub Desktop.
Save gdscbot/bf0d416b7651655ff49c8a922c002503 to your computer and use it in GitHub Desktop.
2023-02-23 Build your own Discord Bot starter
const {
Client, Events, GatewayIntentBits, Partials, ActionRowBuilder, ButtonBuilder
} = require('discord.js');
// Create a new client instance
const client = new Client({
intents: [GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent], partials: [Partials.Message]
});
client.once(Events.ClientReady, c => {
console.log(`Ready! Logged in as ${c.user.tag}`);
});
client.on('interactionCreate', (interaction) => {
if (interaction.isButton()) {
if (interaction.customId === 'cat') {
interaction.reply({
content: `Here is your cat <@${interaction.user.id}>!`,
files: [{attachment: 'https://cataas.com/cat', name: 'cat.jpg'}]
})
}
interaction.message.delete()
}
})
client.on('messageCreate', message => {
if (message.author.bot) {
return
}
console.log(message.content)
switch (message.content) {
case "!options":
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('cat')
.setLabel('Click me for cuteness!')
.setStyle('Primary'),
);
message.reply({components: [row]})
return
}
if (message.channel.id === "1078426178139988019") {
message.reply('Hello there <@' + message.author.id + '>')
}
})
client.login(require('./config.json').token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment