forked from notunderctrl/discordjs-v14-series
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit - Part 1, Part 2, Part 3
- Loading branch information
0 parents
commit 18efa80
Showing
11 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TOKEN = YOUR_BOT_TOKEN |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "discord-bot", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"discord.js": "^14.7.1", | ||
"dotenv": "^16.0.3" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require('dotenv').config(); | ||
const { Client, IntentsBitField } = require('discord.js'); | ||
|
||
const client = new Client({ | ||
intents: [ | ||
IntentsBitField.Flags.Guilds, | ||
IntentsBitField.Flags.GuildMembers, | ||
IntentsBitField.Flags.GuildMessages, | ||
IntentsBitField.Flags.MessageContent, | ||
], | ||
}); | ||
|
||
client.on('ready', (c) => { | ||
console.log(`✅ ${c.user.tag} is online.`); | ||
}); | ||
|
||
client.on('messageCreate', (message) => { | ||
if (message.author.bot) { | ||
return; | ||
} | ||
|
||
if (message.content === 'hello') { | ||
message.reply('hello'); | ||
} | ||
}); | ||
|
||
client.login(process.env.TOKEN); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TOKEN = YOUR_BOT_TOKEN | ||
CLIENT_ID = YOUR_BOT_ID | ||
GUILD_ID = YOUR_SERVER_ID |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "discord-bot", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"discord.js": "^14.7.1", | ||
"dotenv": "^16.0.3" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require('dotenv').config(); | ||
const { Client, IntentsBitField } = require('discord.js'); | ||
|
||
const client = new Client({ | ||
intents: [ | ||
IntentsBitField.Flags.Guilds, | ||
IntentsBitField.Flags.GuildMembers, | ||
IntentsBitField.Flags.GuildMessages, | ||
IntentsBitField.Flags.MessageContent, | ||
], | ||
}); | ||
|
||
client.on('ready', (c) => { | ||
console.log(`✅ ${c.user.tag} is online.`); | ||
}); | ||
|
||
client.on('interactionCreate', (interaction) => { | ||
if (!interaction.isChatInputCommand()) return; | ||
|
||
if (interaction.commandName === 'hey') { | ||
return interaction.reply('hey!'); | ||
} | ||
|
||
if (interaction.commandName === 'ping') { | ||
return interaction.reply('Pong!'); | ||
} | ||
}); | ||
|
||
client.login(process.env.TOKEN); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require('dotenv').config(); | ||
const { REST, Routes } = require('discord.js'); | ||
|
||
const commands = [ | ||
{ | ||
name: 'hey', | ||
description: 'Replies with hey!', | ||
}, | ||
{ | ||
name: 'ping', | ||
description: 'Pong!', | ||
}, | ||
]; | ||
|
||
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN); | ||
|
||
(async () => { | ||
try { | ||
console.log('Registering slash commands...'); | ||
|
||
await rest.put( | ||
Routes.applicationGuildCommands( | ||
process.env.CLIENT_ID, | ||
process.env.GUILD_ID | ||
), | ||
{ body: commands } | ||
); | ||
|
||
console.log('Slash commands were registered successfully!'); | ||
} catch (error) { | ||
console.log(`There was an error: ${error}`); | ||
} | ||
})(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TOKEN = YOUR_BOT_TOKEN | ||
CLIENT_ID = YOUR_BOT_ID | ||
GUILD_ID = YOUR_SERVER_ID |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "discord-bot", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"discord.js": "^14.7.1", | ||
"dotenv": "^16.0.3" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require('dotenv').config(); | ||
const { Client, IntentsBitField } = require('discord.js'); | ||
|
||
const client = new Client({ | ||
intents: [ | ||
IntentsBitField.Flags.Guilds, | ||
IntentsBitField.Flags.GuildMembers, | ||
IntentsBitField.Flags.GuildMessages, | ||
IntentsBitField.Flags.MessageContent, | ||
], | ||
}); | ||
|
||
client.on('ready', (c) => { | ||
console.log(`✅ ${c.user.tag} is online.`); | ||
}); | ||
|
||
client.on('interactionCreate', (interaction) => { | ||
if (!interaction.isChatInputCommand()) return; | ||
|
||
if (interaction.commandName === 'add') { | ||
const num1 = interaction.options.get('first-number').value; | ||
const num2 = interaction.options.get('second-number').value; | ||
|
||
interaction.reply(`The sum is ${num1 + num2}`); | ||
} | ||
}); | ||
|
||
client.login(process.env.TOKEN); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require('dotenv').config(); | ||
const { REST, Routes, ApplicationCommandOptionType } = require('discord.js'); | ||
|
||
const commands = [ | ||
{ | ||
name: 'add', | ||
description: 'Adds two numbers.', | ||
options: [ | ||
{ | ||
name: 'first-number', | ||
description: 'The first number.', | ||
type: ApplicationCommandOptionType.String, | ||
choices: [ | ||
{ | ||
name: 'one', | ||
value: '1', | ||
}, | ||
{ | ||
name: 'two', | ||
value: '2', | ||
}, | ||
{ | ||
name: 'three', | ||
value: '3', | ||
}, | ||
], | ||
required: true, | ||
}, | ||
{ | ||
name: 'second-number', | ||
description: 'The second number.', | ||
type: ApplicationCommandOptionType.Number, | ||
required: true, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN); | ||
|
||
(async () => { | ||
try { | ||
console.log('Registering slash commands...'); | ||
|
||
await rest.put( | ||
Routes.applicationGuildCommands( | ||
process.env.CLIENT_ID, | ||
process.env.GUILD_ID | ||
), | ||
{ body: commands } | ||
); | ||
|
||
console.log('Slash commands were registered successfully!'); | ||
} catch (error) { | ||
console.log(`There was an error: ${error}`); | ||
} | ||
})(); |