我的机器人上有此命令,您可以使用g!mute命令使某人静音,其中使用@提及“用户”。但是,如果您没有提及例如GeoGeo而不是@GeoGeo,则会导致漫游器崩溃。我知道你需要放.catch(console.error);某个地方,但我不确定在哪里。提前致谢。错误是
let person = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[1]))
^
TypeError: message.guild.members.get is not a function
代码:
const Discord = require('discord.js');
const ms = require('ms');
module.exports = {
name: 'mute',
description: "this is mute command",
execute(message, args){
if(!message.member.roles.cache.find(r => r.name ==="Staff", "Head Staff", "Owner", "Co-Owner")) return message.channel.send(`YOU DO NOT HAVE PERMISSION TO DO THAT`)
let members = args[0];
if(!members) return message.reply("g!mute <user> <time>")
let person = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[1]))
if(!person) return message.reply("That person is not in the server!");
let mainrole = message.guild.roles.cache.find(role => role.name === "Fans");
let muterole = message.guild.roles.cache.find(role => role.name === "muted");
if(!muterole) return message.reply("That role does not exist");
let time = args[1];
if(!time){
return message.reply("g!mute <user> <time>");
}
person.roles.remove(mainrole.id);
person.roles.add(muterole.id);
const embed = new Discord.MessageEmbed()
.setTitle ("Muted:")
.setDescription (`${person.user.tag} has now been muted for ${ms(ms(time))}`)
.setColor(0x01B8FF)
message.channel.send(embed);
setTimeout(function(){
person.roles.add(mainrole.id)
person.roles.remove(muterole.id)
const embed = new Discord.MessageEmbed()
.setTitle ("Muted:")
.setDescription (`${person.user.tag} has been unmuted`)
.setColor(0x01B8FF)
message.channel.send(embed);
}, ms(time));
}
}
答案 0 :(得分:2)
遇到类似TypeError: message.guild.members.get is not a function
逻辑上要做的事情是检查文档,以确保message.guild.members
确实具有一个名为get
的函数。这是文档:https://discord.js.org/#docs/main/stable/class/GuildMemberManager
否get
。但是有一个cache
,就像您在代码的其他地方使用的一样。只需检查一下文档,您就能知道您现有的代码是错误的(已过时),您需要像在代码中的其他地方一样使用cache
:
message.guild.members.cache.get(args[1])