node.js - 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("✅")
await msg.react("❌")
})
} 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])
})
}
}
}
解决方案
在这一行中,您应该检查的question
是questionRe
if (!question || question.length === 0) return message.args("You did not provide question")
推荐阅读
- r - 如何制作一个带有多个类的 ggplot2 条形图?
- reactjs - 如何将 Typescript 与 React Router 一起使用并进行匹配
- html - 我的 div 卡在其他 div 之间,不会在底部
- css - 如何将图像保留在其响应式 div 中
- java - 如何更新只有一个字段的sqlite数据库要更改
- laravel-5 - 将 SQL 查询转换为 Eloquent 时遇到问题
- javascript - 如何使用 Jest 存根类的所有方法?
- python - 修改字符串 pandas 中阻塞七位数字
- android - Foreach 没有得到正确的值
- android - 为什么 ImageView 不会移动?