Discord.js 如何缓存按钮
Discord.js how to cache buttons
我想发出一个轮询命令,它工作得很好,直到机器人重新启动。之后,每当单击一个按钮时,它都会说 button.clicker.user 为空。我尝试使用 button.fetch()
但这不是一个函数。这是我当前的代码:
client.on('clickButton', async button => {
try {
await button.fetch(); //not a function
} catch(err) {
console.log(err);
}
try {
await button.clicker.fetch();
} catch(err) {
console.log(err)
}
try {
await button.message.fetch();
} catch(err) {
console.log(err)
}
console.log(button.partial); //undefined so I had to use no condition
if(!button.message.author === client.user) return;
var checkVoted = new RegExp(`${button.clicker.user.tag}:.+`); //error says cannot read tag of null if I restarted bot
var a = [];
我的目标:允许用户点击按钮 属性 即使在节点进程重新启动后
您在问题中提供的代码应该已经可以使用了。
您正在使用 await button.clicker.fetch();
,它将获取答题器的用户和成员属性。
client.on('clickButton', async button => {
console.log(button.clicker); // { user: null, member: null, fetch: [AsyncFunction: fetch] }
await button.clicker.fetch();
console.log(button.clicker.user.tag); // username#1234
})
我想发出一个轮询命令,它工作得很好,直到机器人重新启动。之后,每当单击一个按钮时,它都会说 button.clicker.user 为空。我尝试使用 button.fetch()
但这不是一个函数。这是我当前的代码:
client.on('clickButton', async button => {
try {
await button.fetch(); //not a function
} catch(err) {
console.log(err);
}
try {
await button.clicker.fetch();
} catch(err) {
console.log(err)
}
try {
await button.message.fetch();
} catch(err) {
console.log(err)
}
console.log(button.partial); //undefined so I had to use no condition
if(!button.message.author === client.user) return;
var checkVoted = new RegExp(`${button.clicker.user.tag}:.+`); //error says cannot read tag of null if I restarted bot
var a = [];
我的目标:允许用户点击按钮 属性 即使在节点进程重新启动后
您在问题中提供的代码应该已经可以使用了。
您正在使用 await button.clicker.fetch();
,它将获取答题器的用户和成员属性。
client.on('clickButton', async button => {
console.log(button.clicker); // { user: null, member: null, fetch: [AsyncFunction: fetch] }
await button.clicker.fetch();
console.log(button.clicker.user.tag); // username#1234
})