【问题标题】:I want a command that sends an embed with all the servers that the bot is in我想要一个命令,该命令发送包含该机器人所在的所有服务器的嵌入
【发布时间】:2021-05-05 07:33:51
【问题描述】:

我创建了一个 discord.js 机器人,一段时间后我想添加一个服务器列表命令 为每个服务器发送一条嵌入的消息,其中包含:Server NameMember CountServer Avatar (As The Embed Thumbnail)Server Owner ID 和最重要的是,我不希望任何人能够使用这个命令,除了我,所以也许我添加我的 ID 是常数? 我真的想不出它的代码,但无论如何......这是其中一个命令的格式:

if((args[0] === settings.prefix + "deletereactions" || args[0] === settings.prefix + "dr") && msg.member.hasPermission("ADMINISTRATOR")){
        //deletereactions #channel
        let channel = msg.mentions.channels.array()[0];
        if(!channel) return;
        let db = client1.db("rbot");
        let collection = db.collection("reactions");
        collection.deleteOne({channel : channel.id}, function(err){
            if(err) console.log(err);
            msg.reply("**✅ Done!**");
        })
    }
})

这是我的命令处理程序:

const settings = require("./settings.json");
const Discord = require("discord.js");
const client = new Discord.Client();
const fs = require("fs");
const MongoClient = require("mongodb").MongoClient;
const url = "my_mongodb_url";
const mongoClient = new MongoClient(url, { useUnifiedTopology: true });
const moment = require("moment");
const { CommandCursor } = require("mongodb");

let client1;


client.login(settings.token);

client.on("ready", ready =>{
    console.log("Ready");
    mongoClient.connect(function(err, cli){
        client1 = cli;
    })
    client.user.setActivity(`${settings.activity}`, { type: 'LISTENING' })
})

client.on("message", async msg =>{
    let args = msg.content.split(' ');
    if(msg.channel.type !== "text") return;
    if(msg.channel.type === "text"){
        let db = client1.db("rbot");
        let collection = db.collection("reactions");
        collection.findOne({channel : msg.channel.id}, function(err, result){
            if(err) console.log(err);
            if(result){
                for(let i = 0; i < result.reactions.length; i++){
                    msg.react(result.reactions[i]).catch(err =>{
                        if(err) collection.deleteOne({channel : msg.channel.id}, function(err){
                            if(err) console.log(err);
                        })
                    });

【问题讨论】:

    标签: javascript node.js discord discord.js bots


    【解决方案1】:

    在您的命令中(运行或执行函数): 对于 1 个用户:

    if (message.author.id != "YOUR ID") return;
    

    对于 2 位以上的用户:

    let Owners = ["ID 1", "ID 2"];
    if (!Owners.includes(message.author.id)) return;
    

    例如:

    module.exports = {
      name: "eval",
      run: async (client, message, args) => {
        if (message.author.id != "696969696969") return message.channel.send("Only Owners Can Use Eval Command!");
    
       //...
      }
    };
    

    链接:
    User#id
    Array

    【讨论】:

    • 谢谢,我就是这样才能让命令只对我有用,你知道我怎样才能获取服务器信息吗?
    猜你喜欢
    • 2021-02-02
    • 2021-04-21
    • 2010-09-29
    • 2021-05-11
    • 2021-07-30
    • 1970-01-01
    • 2019-12-18
    • 2018-05-02
    • 2019-06-06
    相关资源
    最近更新 更多