我希望我的机器人每30分钟编辑一次角色。我不确定该怎么做,所以我看了另一个线程。这是代码:
client.on('ready', () => {
var colors = ['#8585ff','#fff681','#a073fd','#fd73b9'];
var random = Math.floor(Math.random() * colors.length);
var role = message.guild.roles.find("name", "Admin");
setInterval(() => {
role.edit({
color: colors[random]
})
}, 1800000);
})
我尝试运行此代码,但是出现以下错误:
(node:95) UnhandledPromiseRejectionWarning: ReferenceError: message is not defined
(node:95) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:95) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
你能帮帮我吗?提前谢谢
答案 0 :(得分:0)
在Client#ready
事件中,默认情况下没有Message
对象,因此您将无法使用Message.guild
属性。
相反,您必须从Guild
获取GuildManager
。 (Client#guilds
)
client.on("ready", () => {
const Guild = client.guilds.cache.get("GuildID");
if (!Guild) return console.error("Couldn't find the guild.");
const Role = Guild.roles.cache.find(role => role.name == "Admin");
// You should really use the ES6 syntax for this.
// Instead of: Guild.roles.find("name", "Admin");
if (!Role) return console.error("Couldn't find the role.");
// Your code here.
});
client.on("ready", () => {
const Guild = client.guilds.get("GuildID");
if (!Guild) return console.error("Couldn't find the guild.");
const Role = Guild.roles.find(role => role.name == "Admin");
if (!Role) return console.error("Couldn't find the role.");
});