0

I develop rule system, but there is a problem. When I type !rule 1 I want to send rule 1 , but error says: Cannot send an empty message

There is the code:

const Discord = require('discord.js');
const fs = require('fs')
module.exports = {
    name: 'rules',
    guildOnly: true,
    async execute(message, args) {
        const rules = JSON.parse(fs.readFileSync("./rules.json", 'utf8'));
        message.channel.send(rules.args.slice(1).join(" "))
    }
}

json file :

{
    "rule1": "**Admins and Discord Mods have the final judgement. If asked to stop, stop.**",
    "rule2": "Be respectful, civil, and welcoming. Sometimes discussion can get heated, but you are responsible for your own behavior.",
    "rule3": "No insults, racism, sexism, homophobia, transphobia, and other kinds of discriminatory speech. We do not welcome these types of speech.",
    "rule4": "No NSFW content (including chat, avatars, and nicknames).",
    "rule5": "Do not join the server to promote your content.\nDo not advertise streams, YouTube channels, Discord servers, Reddit posts, and referral links.",
    "rule6": "Unsolicited advertisements sent to members via private messages will result in instant removal from the server.",
    "rule7": "Do not solicit, buy, sell, trade, give away, or beg for accounts, cheats, **boosting**, RP, codes, money, referrals, or other goods.",
    "rule8": "This is not a dating server: e-dating, fawning, excessive flirting, role-playing, and other similar behavior are not allowed.",
    "rule9": ""
}

1 Answers1

0

args is not a property of the rules object. Instead, you could do something like this using the Object.entries() function:

// const rules = JSON.parse(fs.readFileSync("./rules.json", 'utf8'));

const rules = {
  "rule1": "**Admins and Discord Mods have the final judgement. If asked to stop, stop.**",
  "rule2": "Be respectful, civil, and welcoming. Sometimes discussion can get heated, but you are responsible for your own behavior.",
  "rule3": "No insults, racism, sexism, homophobia, transphobia, and other kinds of discriminatory speech. We do not welcome these types of speech.",
  "rule4": "No NSFW content (including chat, avatars, and nicknames).",
  "rule5": "Do not join the server to promote your content.\nDo not advertise streams, YouTube channels, Discord servers, Reddit posts, and referral links.",
  "rule6": "Unsolicited advertisements sent to members via private messages will result in instant removal from the server.",
  "rule7": "Do not solicit, buy, sell, trade, give away, or beg for accounts, cheats, **boosting**, RP, codes, money, referrals, or other goods.",
  "rule8": "This is not a dating server: e-dating, fawning, excessive flirting, role-playing, and other similar behavior are not allowed.",
  "rule9": ""
};


// you can use this function to get all the rules, separated by 2 line breaks
console.log(Object.entries(rules).map(rule => rule.join(': ')).join('\n\n'))
Lioness100
  • 8,260
  • 6
  • 18
  • 49