首页 > 解决方案 > Discord.js 轮询命令无法读取 null 的属性“0”

问题描述

我正在尝试创建一个 Discord.js 轮询命令,我不断收到此错误无法读取 null 的属性“0”,我们将不胜感激。我不知道如何解决我已经尝试了很多不同的方法,但它们都不起作用:(

const { MessageEmbed } = require('discord.js')
module.exports = {
    name : 'poll',
    category : 'util',
    cooldown: 5,
    description : 'Makes a poll',
    permissions: ["MANAGE_MESSAGES"],


    run : async(client, message, args) => {
let num = {
    1: '1️⃣',
    2: '2️⃣',
    3: '3️⃣',
    4: '4️⃣',
    5: '5️⃣',
    6: '6️⃣',
    7: '7️⃣',
    8: '8️⃣',
    9: '9️⃣',
    10: ''
}

var questionRe = /"(.*)"/gmi
        let question = args.join(" ").match(questionRe)

        if (!questionRe) return message.args("You did not provide question")
        let options = args.join(" ").slice(question[0].length).split(" | ")
        let result = ""
        
        
        if (options.length <= 1) {
            result += "✅ : Yes\n"
            result += "❌ : No"

            return message.send(` ${question}`, `React with one of the following to determine your choice!\n${result}`, "BLUE").then(async msg => {
                await msg.react("✅&quot;)
                await msg.react("❌&quot;)
            })

        } else {
            if (options.length > 9) return message.error("Cannot be more than 9 options")
            result = options.map((c, i) => {
                return `${num[i + 1]}: ${c}`
            })
            let msg = await message.sendE(` ${question}`, `React with one of the following to determine your choice!\n${result.join('\n')}`, "BLUE")
            options.map(async (c, x) => {
                await msg.react(num[x + 1])
            })
        }
    }
}

标签: node.jsdiscorddiscord.js

解决方案


在这一行中,您应该检查的questionquestionRe

        if (!question || question.length === 0) return message.args("You did not provide question")

推荐阅读