本文介绍了是否可以禁止不在不和谐服务器中的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始用JavaScript制作Discord机器人.我使自己的漫游器具有禁止人员的功能,并且成功禁止了服务器中的人员,但是我想知道是否有办法可以禁止离开服务器或什至从未加入服务器的人员.

I recently started on making my discord bot in javascript. I made my own bot have the power of banning people and it successfully bans people that are IN the server, but I wanted to know if there was a way I can ban people that left the server or even never joined the server.

const bUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));

if(!bUser) return message.channel.send("Couldn't find user.");

message.guild.member(bUser).ban(banreason);

return message.channel.send("User " + bUser + " was banned");

当我禁止不在服务器中的某人时,它说:找不到用户."

When I ban someone not in the server it says: "Couldn't find user."

推荐答案

您可以使用 Guild.ban() 方法,该方法使用用户而不是GuildMember.

You can use the Guild.ban() method which uses a User instead of a GuildMember.

示例:

// async context

try {
  const user = message.mentions.users.first() || await client.fetchUser(args[0]);
  if (!user) return await message.channel.send('Unable to find user.');

  const reason = args.slice(1).join(' ') || 'No reason provided';

  await message.guild.ban(user, { reason: reason });
} catch(err) {
  console.error(err);
}

这篇关于是否可以禁止不在不和谐服务器中的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 10:43