discord - 变量未传递给模块
问题描述
我无法让我的变量之一传递给命令模块。它在声明const { token, ownerid, botid } = require('./config.json');
并通过command.execute(message, args, prefix, ownerid);
并通读,execute(message, args, prefix, ownerid) {
但是当我尝试在模块中记录 ownerid 时,它显示为未定义。我想它在某处被抹去。我尝试在 command.execute 之前记录它,它在那里读得很好,我认为它以某种方式迷路了。
哦,这就是 ownerid 的样子:([ 'xxxxxxxxxxxxxx' ]
但显然有数字)有人知道我的变量去了哪里吗?
我的临时解决方案是使用 fs 来读取模块中的文件,而不是导入变量。
代码:按使用顺序:
const { token, ownerid, botid } = require('./config.json'); //declared
//command defined
client.commands = new Discord.Collection();
const commandFolders = fs.readdirSync('./commands');
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const commandfile = require(`./commands/${folder}/${file}`);
client.commands.set(commandfile.name, commandfile);
}
}
client.on('message', message => {
//filters and stuff
try {
command.execute(message, args, prefix, ownerid);
} catch (error) {
console.error(error);
message.reply('There was an error trying to execute that command!');
}
});
//in module
execute(message, args, prefix, ownerid) {
for (let i = 0; i < ownerid.length; i++) {
const dmme = message.client.users.cache.get(ownerid[i])
const bugreportembed = new Discord.MessageEmbed()
.setTitle('New bug report!')
.addField('Info', `From ${message.author.tag}`)
.setColor('RANDOM')
.addField('Description', message.content.replace(`${prefix}bugreport `, ""))
dmme.send(bugreportembed)
message.channel.send('Sent!')
}
}
解决方案
推荐阅读
- functional-programming - 有没有更好的功能方法来处理带有错误检查的向量?
- react-native - StackNavigation 道具未按预期工作
- android - 如何在选定的卡片视图上点击波纹和其他前景?
- wordpress - 强制 Woocommerce 按属性过滤以仅显示搜索词在标题中的属性
- audio - 处理坚持 pause() 不是一个函数,当它非常重要时
- python - 从图像中去除噪点
- google-cloud-platform - 从 Cloudfunctions 提交 Cloudbuild 作业时出错,如果
- string - 如何使用 VB6 获取此字符串的每一行
- sparql - 创建资源中三元组的 SPARQL CONSTRUCT 命令顺序
- functional-programming - 在 F# 中并行柯里化多个函数