Created
February 23, 2023 22:49
-
-
Save gdscbot/bf0d416b7651655ff49c8a922c002503 to your computer and use it in GitHub Desktop.
2023-02-23 Build your own Discord Bot starter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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