Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Discord.js 如何";“全球范围内”;将使用我的discord机器人的用户列入黑名单?_Discord.js - Fatal编程技术网

Discord.js 如何";“全球范围内”;将使用我的discord机器人的用户列入黑名单?

Discord.js 如何";“全球范围内”;将使用我的discord机器人的用户列入黑名单?,discord.js,Discord.js,就其本身而言,它是有效的,除了我可以只发送一个用户ID的部分,该ID将用户列入黑名单。 只要成员在运行命令的服务器中,它就可以工作。用DJS和猫鼬编码 const mongoose = require("mongoose") module.exports = { name: "blacklist", aliases: ["b", "block"], cooldown: 5000, d

就其本身而言,它是有效的,除了我可以只发送一个用户ID的部分,该ID将用户列入黑名单。 只要成员在运行命令的服务器中,它就可以工作。用DJS和猫鼬编码

const mongoose = require("mongoose")

module.exports = {
    name: "blacklist",
    aliases: ["b", "block"],
    cooldown: 5000,
    description: "Blocks a user from using Hexagon!",
    devOnly: true,
    category: "Developer",
    usage: "blacklist <user> [reason]",

    async run(client, message, args) {
        if(!args[0]) return message.reply('`[❌]` Incorrect Syntax: Missing Argument')

        const mentionedUser = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || client.users.cache.fetch(args[0]);
        if(!mentionedUser) return message.reply('`[❌]` Incorrect Syntax: Provided User does not exist!')

        let reason = args.slice(1).join(" ")
        if(!reason) reason = "Reason not specified."

        let profile = blacklistedUsers.findOne({userID: mentionedUser.user.id})
        
        if(profile) return message.reply('`[❌]` Error: Mentioned User is already blacklisted!')

        profile = await new blacklistedUsers({
            userID: mentionedUser.user.id,
            reason
        }).save();
        message.channel.send(`\`❌The way I would do this, is in your handler, use a 
string.includes
to check blacklisted ids (hopefully separated by commas or such) and check if any match.

//for example:
let tableExample; //mongoose table I use for the object, change to your needs

if (tableExample.blacklistedIDs.includes(message.author.id)) return;

//obviously I use blacklistedIDs, change this to your needs also
const mongoose=require(“mongoose”)
module.exports={
名称:“黑名单”,
别名:[“b”,“块”],
冷却时间:5000,
description:“阻止用户使用Hexagon!”,
诚然,
类别:“开发者”,
用法:“黑名单[原因]”,
异步运行(客户端、消息、参数){
if(!args[0])返回消息。回复('`[❌]` 语法不正确:缺少参数“)
const-sindeduser=message.sindements.members.first()| | message.guild.members.cache.get(args[0])| | | client.users.cache.fetch(args[0]);
如果(!indicatedUser)返回消息。回复('`[❌]` 语法不正确:提供的用户不存在!')
让reason=args.slice(1.join)(“”)
如果(!reason)reason=“未指定原因。”
let profile=blacklistedUsers.findOne({userID:sineteduser.user.id})
if(配置文件)返回消息。回复('`[❌]` 错误:提到的用户已被列入黑名单!')
profile=等待新的黑名单用户({
userID:referenceduser.user.id,
原因
}).save();

message.channel.send(`\`❌ 我这样做的方法是,在处理程序中,使用
字符串。includes
检查黑名单ID(希望用逗号等分隔),并检查是否有匹配项

//例如:
let tableExample;//我用于对象的mongoose表,根据需要更改
if(tableExample.blacklistedis.includes(message.author.id))返回;
//显然,我使用Blacklisted,也可以根据您的需要更改此选项

此方法将检查数据库中的任何id,如果它与运行命令时的用户id匹配,它将取消。

谢谢,但这不是主要问题。我希望能够将用户列入黑名单,而不让他们出现在运行命令的服务器中。是的,这仍然很简单,您只需要用户id并将其添加到BlacklistedDS fi中即可eld-此代码用于当黑名单用户运行任何命令时,您需要将其放入您的处理程序中。但随后我需要手动添加ID,因为该命令仅在用户在服务器中时有效。您还打算添加黑名单ID吗?当然!blacklist命令会将ID添加到数据库中吗?-以及使用met如上文所述,用户将永远无法在任何服务器上使用命令。!黑名单仅在用户位于服务器上时有效,但我希望将与我不在同一服务器上但与我的机器人共享服务器的用户列入黑名单