【问题标题】:issue with creating role and channel automatically from private message with bot使用机器人从私人消息中自动创建角色和频道的问题
【发布时间】:2019-06-29 08:25:48
【问题描述】:

不确定创建通道和创建角色在下面的代码中是如何工作的,朝向底部。 (编辑:没有任何东西发送到控制台,代码也没有发生任何事情。就像它被完全忽略了一样。)这是来自用户 A 挑战用户 B 的代码的 sn-p。用户 B 收到消息,提醒他们挑战已通过私人消息发给他们。如果挑战被接受,我希望机器人 1) 为用户 A 和用户 B 创建一个名为“用户 A 与用户 B”的角色 2) 将用户 A 和用户 B 放入该新角色中 3)在机器人所在服务器的特定类别中创建一个名为“User A vs User B”的战场。

我不确定问题是否在于机器人如何尝试在服务器中创建角色和通道,而机器人在私人消息中而不是在服务器上与用户交谈。我认为将“服务器”变量作为服务器 ID 会有所帮助,但在接受消息之后它似乎没有做任何事情。

// Awaits reply from user
if (message.channel.id === '541736552582086656') return target.send("Do you accept the challenge? Please reply with 'accept' or 'deny'.")
  .then((newmsg) => {
    newmsg.channel.awaitMessages(response => response.content, {
      max: 1,
      time: 150000,
      errors: ['time'],
    }).then((collected) => {
        // Grabs the first (and only) message from the collection.
        const reply = collected.first();
      
        if (reply.content === 'accept'){
          reply.channel.send(`You have ***accepted *** the challenge from ${challenger}. Please wait while your battlefield is made...`);
          message.author.send(`${target} has accepted your challenge! Please wait while the channel is made for your brawl...`)
/// Problems start here
          function createChannel(message){
            var server = "SERVER ID";
            var name = `${target} vs ${challenger}`;
            message.guild.createRole({
                role: {
                    name: `${target} vs ${challenger}`,
                    color: "#00fffa",
                    permissions: [] }
            }).then(role => {
                target.addRole(role, name)
                challenger.addRole(role, name)
                .catch(error => client.catch(error))
            }).catch(error => client.catch(error))
            server.createChannel(Name, name).then(
                (channel) => {
                    channel.setParent("CATEGORY ID")
          })
        } // problems end here
        } else if (reply.content === 'deny') {
          reply.channel.send("You have ***denied *** the challenge.") 
        } else {
          reply.channel.send("Your response wasn't valid.");
        }
      })
   })
}

我一直想知道是否需要以不同的方式制作频道和角色,因为它试图通过私人消息而不是在服务器内部制作..

感谢您的任何帮助!如果我为此类问题过多地使用堆栈溢出,我也深表歉意......你们很擅长帮助我了解做事的不同方式以及我做错了什么,所以我正在学习,但我没有想要觉得我滥用它太多了。

【问题讨论】:

  • 你有什么错误?
  • 你说的是你所期望的,但在这样的问题中,你必须提供你所期望的以及当前发生的情况
  • 什么也没发生。代码可以完美运行,直到我指定的点。没有错误代码或任何内容发送到控制台。就像代码被完全忽略了一样。

标签: node.js roles channel discord.js


【解决方案1】:

我认为问题在于您使用代码创建了一个名为createChannel 的函数来创建角色和频道,但您从未调用过该函数。

您可以在声明后调用该函数,或者(我认为这更好)您可以删除以下行

function createChannel(message){

} // problems end here

【讨论】:

  • 这完美解决了我的问题!谢谢!
猜你喜欢
  • 2017-09-02
  • 2018-11-19
  • 1970-01-01
  • 1970-01-01
  • 2021-10-30
  • 2022-07-17
  • 1970-01-01
  • 1970-01-01
  • 2018-04-01
相关资源
最近更新 更多