【问题标题】:Discord.js Create webhook in every channel on serverDiscord.js 在服务器上的每个通道中创建 webhook
【发布时间】:2020-08-29 08:20:25
【问题描述】:

您好,我如何使用 discord.js 在特定公会的每个频道中创建 webhook(具有相同的名称和头像)? 以及如何使用 discord.js 在特定通道中使用第一个 webhook 获取第一个 webhook 并发送消息?

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    我不知道,但如果你添加了这个命令,它应该可以工作。在每个频道中运行它

    const prefix = '';
    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    
    if (msg.content === `${prefix}createwebhook`) {
      let name = args.slice(1).join(" ");
      
      //Check for permissions because we don't need everyone making webhooks!
      if(!message.author.hasPermission("MANAGE_WEBHOOKS")) {
        return message.channel.send("You are not authorized to do this!");
      }
      //What if the bot can't do it?
      if(message.guild.me.hasPermission("MANAGE_WEBHOOKS")) {
        return message.channel.send("I have not been allowed to make webhooks!");
      }
    
      message.channel.createWebhook(name, {
        avatar: args[1], // So when doing this command, you must give it an image URL (Should end in .jpg, .png, etc.)
    }).then(webhook => console.log(`Created webhook ${webhook}`)).catch(console.error);
    
      message.channel.send(`${message.author}, created the webhook "${webhook}" with the profile picture ${args[0]}`);
      }
    

    文档可以在here找到

    【讨论】:

      猜你喜欢
      • 2019-08-22
      • 1970-01-01
      • 1970-01-01
      • 2021-05-03
      • 2021-03-20
      • 2021-01-22
      • 2019-07-14
      • 2021-02-16
      • 2016-07-16
      相关资源
      最近更新 更多