admin管理员组文章数量:1415484
I'm kinda new to coding discord bots and I have a problem. I want to have a ban mand that would ban the mentioned user in the mand or the user that has an ID that was provided in the mand. For example: &ban @User#0001 would ban User#0001 but if the mand looks like this: &ban 123456789123456789 (let's say that's the ID of User#0001) it would still ban User#0001 (as it is the user's ID).
I have this code, it works if I mention the user, but it doesn't work if I enter the ID.
const Discord = require('discord.js');
module.exports = {
name: 'testban',
description: "Executer will ban the mentioned user",
execute(message, args){
if (!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send("Invalid Permissions")
let User = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
if (!User) return message.channel.send("Invalid User")
if (User.hasPermission("BAN_MEMBERS")) return message.reply("Can't ban that one, he also can ban")
let banReason = args.join(" ").slice(22);
if (!banReason) {
banReason = "None"
}
console.log(`USER = ${User}`)
User.ban({reason: banReason})
var UserID = User.id
console.log(`USER ID = ${UserID}`)
}
}
The error I get when entering the ID is this:
message.guild.members.get is not a function
How could I make it ban the person even if I only provide the ID?
I'm kinda new to coding discord bots and I have a problem. I want to have a ban mand that would ban the mentioned user in the mand or the user that has an ID that was provided in the mand. For example: &ban @User#0001 would ban User#0001 but if the mand looks like this: &ban 123456789123456789 (let's say that's the ID of User#0001) it would still ban User#0001 (as it is the user's ID).
I have this code, it works if I mention the user, but it doesn't work if I enter the ID.
const Discord = require('discord.js');
module.exports = {
name: 'testban',
description: "Executer will ban the mentioned user",
execute(message, args){
if (!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send("Invalid Permissions")
let User = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
if (!User) return message.channel.send("Invalid User")
if (User.hasPermission("BAN_MEMBERS")) return message.reply("Can't ban that one, he also can ban")
let banReason = args.join(" ").slice(22);
if (!banReason) {
banReason = "None"
}
console.log(`USER = ${User}`)
User.ban({reason: banReason})
var UserID = User.id
console.log(`USER ID = ${UserID}`)
}
}
The error I get when entering the ID is this:
message.guild.members.get is not a function
How could I make it ban the person even if I only provide the ID?
Share Improve this question edited Jul 21, 2021 at 9:40 Pandicon asked Aug 26, 2020 at 13:40 PandiconPandicon 4303 gold badges17 silver badges38 bronze badges 1-
Vinicius's answer is correct, but also make sure you change
message.mentions.users.first()
tomessage.mentions.members.first()
so that it returns aGuildMember
instead of aUser
– Lioness100 Commented Aug 26, 2020 at 15:42
1 Answer
Reset to default 3If you're using the newer versions of discord.js you need to use the cache
, you just need to change it to this:
message.guild.members.cache.get(args[0])
本文标签: javascriptBanning users using user ID discordjsStack Overflow
版权声明:本文标题:javascript - Banning users using user ID discord.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745232761a2648898.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论