简体   繁体   中英

Discord bot is active, but isn't responding to discord inputs. Testing using a simple "ping" embed command

I'm trying to create a discord bot using a different syntax you could say and trying to integrate a bunch of different commands. The original command I was trying to add was the "fees.js" below. And the bot wasn't responding to the command, but isn't crashing in the console either. I tried testing with a simple ping command that would respond with "Pong," within an embed. but still doesn't respond. Below I've attached my index,js. fees,js. and my test ping.js

const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS"] }, { partials: ["MESSAGE", "CHANNEL", "REACTION", "MANAGE_ROLES"] })
require("dotenv").config();

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.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

client.on("messageCreate", message => {
    if (message.author.bot) return;
    if (message.content === prefix + 'reactionrole') {
        if (!message.member.roles.cache.has('885603457938108476')) {
            return message.channel.send('You dont have access to this!');
        }

        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.commands.get("ping").execute(message, args, Discord, client);
        }
    }
});

client.login('Token');

fees.js

module.exports = {
    name: 'fee',
    description: 'This command will calculate the payouts for every major platform\n`!fee <amount>`\nexample: `!fee 100`',
    async execute(message) {
        const fees = {
            'StockX Level 1 (9.5%)': n => .095 * n,
            'StockX Level 2 (9%)': n => .09 * n,
            'StockX Level 3 (8.5%)': n => .085 * n,
            'StockX Level 4 (8%)': n => .08 * n,
            'Goat 90+ (9.5% + $5.00 + 2.9%)': n => 0.095 * n + 5 + (0.905 * n * 0.029),
            'Goat 70-89 (15% + $5.00 + 2.9%)': n => 0.15 * n + 5 + (0.85 * n * 0.029),
            'Goat 50-69 (20% + $5.00 + 2.9%)': n => 0.20 * n + 5 + (0.80 * n * 0.029),
            'Ebay (12.9% + $0.30': n => 0.129 * n + 0.3,
            'Paypal (2.9% + $0.30)': n => (0.029 * n) + 0.3,
            'Grailed (9% + 2.9%)': n => 0.089 * n + 0.911 * n * 0.029,
        }
        const embed = new Discord.MessageEmbed();
        embed.setTitle("Fee Calculator")
        if (msg.content.split(" ").length == 2) {
            if (isNaN(message.content.split(" ")[1])) {
                embed.setDescription('Please input a number');
            }
            else {
                const [, number] = message.content.split(' ');
                Object.keys(fees).forEach(fee => {
                    embed.addField(`${fee} Payout`, `$${Number(number - fees[fee](number)).toFixed(2)}`);
                });
            }
        }
        else if (message.content.split(" ").length > 2) {
            embed.setDescription("This command takes only 1 argument");
        }
        else if (message.content.split(" ").length == 1) {
            embed.setDescription("Please put a price to calculate fees");
        }
        else {
            embed.setDescription("Please input a price")
        }
        message.channel.send(embed);
    }
}

ping.js

module.exports = {
    name: 'ping',
    description: 'This command will display the latency between Discord and our servers\n`!ping`\nexample: `!ping`',
    permission: 'USE_APPLICATION_COMMANDS',
    async execute(message, args, Discord, client) {
            const embed = new Discord.MessageEmbed()
            .setTitle("Ping")
            .setColor('#5104DB')
            .setDescription(`Pong!`)

            message.channel.send({ embeds: [embed] });
        }
    }

On September 1st, Discord made message content a privileged intent. Maybe you should check your application settings over at Discord Developers ? Also you might want to consider switching to Slash Commands.

EDIT :

I noticed that you are checking if the command equals to "reactionrole", before checking for equality to "ping". Maybe try moving the if statement outside of that check?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM