问题描述
我想知道是否可以通过 User ID
禁止某人.通常,要禁止某人,您可以使用
是否可以使用 discord.js
复制此内容?
在对该问题进行研究期间,我偶然发现了.可接受的答案是使用 Guild.ban
函数.
但是,由于在 Guild
类文档,并且相同的答案使用了 fetchUser()
(已弃用的函数),我得出的结论是,它仅在 discord中有效.js v11
.
由于它以前是早期版本中的函数,所以我确定现在还没有找到它的方法.
最后,我知道我可以将 User ID
添加到数组中,并且每当发出 guildMemberAdd
事件时,我都可以检查其 User ID
针对该数组,但是我仍然想知道是否可以通过 User ID
禁止成员.预先感谢!
的文档
在v12中,discord.js将与公会成员进行交互的方法移至了 GuildMemberManager
类,可通过 guild.members
.
您要查找的方法是 GuildMemberManager.ban(id)
.文档上有一个示例:
guild.members.ban('84484653687267328').then(user => console.log(`$ {guild.name}中被禁止的$ {user.username || user.id || user}))).catch(console.error);
I was wondering if it's possible to ban someone via User ID
. Normally, to ban someone, you'd use a GuildMember
and the .ban()
method:
GuildMember.ban()
However, if a user is not in the guild you want to ban them from, it's impossible to get their GuildMember
object. Is there an alternate method?
Using the actual Discord program, it is possible to ban someone before they join by mentioning them with their User ID
(for example: <@123456789012345678>
). Then, you can right-click the mention, and then ban them:
Is there a way to replicate this with discord.js
?
During my research on the problem, I stumbled upon someone asking the same question as me. The accepted answer was to use the Guild.ban
function.
However, since I couldn't find the method in the Guild
class docs, and the same answer used fetchUser()
(a deprecated function), I came to the conclusion that it would only work in discord.js v11
.
Since it was previously a function in an earlier version, I'm sure there's probably still a way to do it now that I haven't found.
Lastly, I know that I could just add the User ID
to an array, and whenever the guildMemberAdd
event is emitted I could check their User ID
against that array, but I'd still like to know if banning a member by User ID
is possible. Thanks in advance!
Edit: Docs for the v11 Guild.ban()
function
In v12 discord.js moved such methods which interact with guild members all to the GuildMemberManager
class, accessible via guild.members
.
The method you're looking for is GuildMemberManager.ban(id)
. There's an example on the docs:
guild.members.ban('84484653687267328')
.then(user => console.log(`Banned ${user.username || user.id || user} from ${guild.name}`))
.catch(console.error);
这篇关于如何禁止不在服务器中的人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!