javascript - 无法读取未定义 discord.js 的属性“公会”
问题描述
我的代码:
module.exports = async (client, message) => {
const guild = client.guilds.cache.get('815676619955503124');
setInterval(() => {
const channelgp = guild.channels.cache.get('815856763114487808');
let myRole = message.guild.roles.cache.get('815855967773786113');
console.log(`${goldpiston.size} person with this role`);
channelgp.setName(`gold piston owner: ${goldpiston.toLocal}`);
console.log('Refreshing...');
}, 5000); }
和错误:
C:\Users\user\Desktop\DiscordBot\counters\roles-counter.js:7
let goldpiston = message.guild.roles.cache.get(roleID).members;
^
TypeError: Cannot read property 'guild' of undefined
at Timeout._onTimeout (C:\Users\user\Desktop\DiscordBot\counters\roles-counter.js:7:34)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
一开始的代码是为了检查谁在线。我改变了它,看看谁有这个角色。
解决方案
不,我只是打电话给客户。这是 main.js,它位于根文件夹中。以前的代码在“counter”文件夹中。
const Discord = require('discord.js');
const client = new Discord.Client();
const memberCounter = require('./counters/member-counter');
const rolesCounter = require('./counters/roles-counter');
const prefix = '$';
client.once('ready', () => {
console.log('2c5t is online!');
memberCounter(client);
rolesCounter(client);
})
client.on('message', message => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'author')
{
message.channel.send('Author is onhq');
console.log('Command used!');
}
})
client.login('ODE1NjYzMDkzMTU2ODA2NjY2.YDvrcw.5XhiBf4SGFyU1hQkye152f2hmdc');
推荐阅读
- javascript - 如何对文档实施黑白滤镜
- fortran - Fortran 代码在 HPC 上使用 mpi_send 时冻结,但在我的笔记本电脑上没有
- flutter-packages - 如何在flutter pub publish中登录/注销?
- java - 从服务器正确解析数据但 Android recyclerview 为空
- angular - 内容在弹性布局角度中没有响应
- weblogic - java独立客户端将war文件部署到weblogic 14.1.1
- solr - 多个术语短语的 SOLR 自动完成
- c# - 如何按属性汇总对象列表
- html - 如何在 div 块之间缩进以使它们不背靠背?
- editor - 在 VS Code 中自定义带引号的字符串