【问题标题】:How do you make a discord bot that creates 'ghost' accounts?你如何制作一个创建“幽灵”帐户的不和谐机器人?
【发布时间】:2020-02-25 05:49:43
【问题描述】:

我见过一些创建“幽灵”帐户来代表用户的机器人,它仍然是同一个机器人,单击上一个迭代会显示当前迭代的名称和个人资料图片,但它从不显示有关用户的信息,就好像它们被删除或离开了服务器一样。

这是一个例子,这个机器人根据用户说话重命名自己,它基本上是一个聊天记录。

在图片中,我点击了第二个用户,您可以看到它是最近使用的用户。 发生这种情况时,原始机器人永远不会更改其名称或任何内容,它实际上就像一个新帐户。

我找不到关于这个主题的任何东西,但人们只是不知怎么知道如何制作这个。

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

    那些“幽灵账户”被称为webhooks。您可以手动创建 webhook(服务器设置 > Webhook > 创建 Webbook)或使用TextChannel.createWebhook(name, [avatar], [reason]) 方法。示例:

    const Discord = require('discord.js');
    const bot = new Discord.Client();
    
    bot.on('message', (message) => {
        if (message.content == "createWebhook") {
            message.channel.createWebhook("My Webhook", "https://support.discordapp.com/system/photos/3602/4079/7511/dan.png", "Reason").then(() => {message.reply("Webhook created!")}).catch((error) => {message.reply("Couldn't create webhook."); return console.log(error)});
        }
    });
    
    bot.login("TOKEN");
    

    使用网络钩子:

    const Discord = require('discord.js');
    const bot = new Discord.Client();
    
    bot.on('message', (message) => {
        if (message.content == "sendWebhook") {
            const Webhook = new Discord.WebhookClient("Webhook ID", "Webhook Token");
            Webhook.send("Hello there!");
        }
    });
    
    bot.login("TOKEN");
    

    您也可以在 HTML 公式中使用它。

    <html>
        <head>
            <link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
            <script src = "https://code.jquery.com/jquery-3.4.1.min.js"></script>
            <title>Send Webhook</title>
        </head>
        <body class = "bg-dark">
            <main class = "container">
                <div class = "card">
                    <div class = "card-header text-center">Send Webhook</div>
                    <div class = "card-body">
                        <div class = "form-group">
                            <form id = "form">
                                <label for = "url">Webhook URL: *</label>
                                <input required type = "text" id = "url" class = "form-control">
    
                                <label for = "message">Webhook Message: *</label>
                                <input required type = "text" id = "message" class = "form-control">
    
                                <hr>
    
                                <label for = "username">Webhook Username:</label>
                                <input type = "text" id = "username" class = "form-control">
    
                                <label for = "avatar">Webhook Avatar:</label>
                               <input type = "text" id = "avatar" class = "form-control">
    
                               <hr>
    
                                <div class = "d-flex justify-content-center">
                                    <button type = "submit" class = "btn btn-outline-primary">Submit</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </main>
            <script>
                $(document).ready(function() {
                    $("#form").submit(function() {
                        var url = $("#url").val();
                        var message = $("#message").val();
                        var username = $("#username").val();
                        var avatar = $("#avatar").val();
    
                        $.post(url, {"content": message, "username": username, "avatar_url": avatar})
                        return false;
                    })
                })
            </script>
        </body>
    </html>

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 2020-11-29
      • 2021-03-13
      • 2021-09-17
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多