script discord bot js
Sure! Here's an example of a basic Discord bot script written in JavaScript:
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '!';
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(' ');
const command = args.shift().toLowerCase();
if (command === 'ping') {
message.channel.send('Pong!');
} else if (command === 'hello') {
message.channel.send('Hello there!');
} // Add more commands here
// Add more commands here
});
client.login('YOUR_BOT_TOKEN');
This script creates a Discord bot using the discord.js library. It listens for messages starting with a specified prefix (in this case, '!') and executes different commands based on the user's input. In the example above, it responds with 'Pong!' when the user types '!ping' and 'Hello there!' when the user types '!hello'.
To use this script, you need to replace 'YOUR_BOT_TOKEN' with the actual token of your Discord bot. You can obtain this token by creating a new bot on the Discord Developer Portal.
Remember to install the discord.js library before running this script by running the command npm install discord.js in your project directory
原文地址: http://www.cveoy.top/t/topic/i0P1 著作权归作者所有。请勿转载和采集!