Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

discord.js - I am attempting to make a discord bot but it will not function

So I would first like to start off by saying I'm really new to coding and this is my first big project. Anyway, I coded my bot and it comes online perfectly fine but will not even do the commands I have coded it to do. I will send the code I have done to make sure I've done it correctly. Here is main.js

main.js


const client = new Discord.Client();

const prefix = '.';

const fs = require('fs');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);

    client.commands.set(command.name, command);
}


client.once('ready', () => {
   console.log('USA is online!');
});

client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;
    
    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();


    if(command === 'ping'){
       client.command.get('ping').execute(message, args, Discord);
        message.channel.send('pong!')
    }
});

```client.login('My discord token is in here so i wont be sharing this part');




Here is the ping.js command I have in a command folder:


ping.js:


```module.exports = {
    name: 'ping',
    description: "if you ping we shall pong.",
    execute(message, args){
        message.channel.send('pong!');
    }
```}



Here is my problem here:

command.js:


```module.exports = {
    name: 'command',
    description: "Embeds!",
    execute(message, args, Discord) {
        const newEmbed = new Discord.MessageEmbed()
        .setColor('#3B5998')
        .setTitle('Rules')
        .setDescription('Basic Server Rules')
        .addFields(
            {name: 'Rule 1', value: 'No blank Nicknames.'},
            {name: 'Rule 2', value: 'No persons under 13 are allowed in here.'},
            {name: 'Rule 3', value: 'No racist,homophobic,transphobic or disturbing content.'},
            {name: 'Rule 4', value: 'No sexually explicit nicknames.'},
            {name: 'Rule 5', value: 'No blank profile pictures.'},
            {name: 'Rule 6', value: 'No Nicknames with unreadable unicode.'},
            {name: 'Rule 7', value: 'No offensive profile pictures.'},
            {name: 'Rule 8', value: 'Moderators reserve the right to kick or ban if they believe you broke a rule..'},
            {name: 'Notice', value: 'Stay safe'}
        )   
        .setImage('https://www.teahub.io/photos/full/21-216454_usa-flag-america-wallpaper-photos.jpg')
        .setFooter('Stay Safe Online');
    
        message.channel.send(newEmbed);
    
    }

```}

I'd really like some help as it would be really neat to see my first project come to life and just make me feel more competent in my abilities,
I have been learning this off of a youtuber called "Code Lyon".

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...