I want the bot to ban member.
Code:
let member = message.guild.members.get(message.author);
if(message.content === message.content && message.channel.id === id)
member.ban("reason")
message.channel.send("x")
So basically, whenever member sends message in specified channel, he will get ban. However, it does not ban. I tried to do it like message.author.id
and so on but not successfully. Also, as I said it does not ban the member, but it sends the "x"
message to the channel. I want to fix the ban problem and that it would send the "x"
message as soon as he gets ban.
CodePudding user response:
<GuildMemberManager>.get
doesn't exist. You should use itsfetch
method, that returns a<GuildMember>
that you can ban using itsban
method. This method returns a Promise so you need toawait
it. So replacelet member = message.guild.members.get(message.author);
withlet member = await message.guild.members.fetch(message.author.id);
The expression
message.content === message.content
shouldn't be a condition as it always returns true.
let member = await message.guild.members.fetch(message.author.id);
if(message.channel.id === id)
member.ban("reason")
message.channel.send("x")
Also don't forget to handle the Promise
rejection of the fetch
, ban
and send
methods.
CodePudding user response:
Can you try this ?
if (!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send(perms)
if (user) {
const member = message.guild.members.resolve(user);
if (member) {
member
.ban({
reason: 'Reason for ban',
})