简化一次性消息通道机器人

时间:2019-02-28 06:11:22

标签: javascript visual-studio discord.js

我基本上是在尝试将代码放入易于使用的位置。基本上成命令了。有两个命令,但是我现在只处理一个。一次性消息通道。我想在其中添加一个频道,如果您在该频道中只说一次,则该漫游器会给您一个角色,禁止您在该频道中讲话。

命令是这个

d!omca roleid channelid

然后将其添加到机器人中。

这是我使用的代码。

    var commando = require('discord.js-commando');
var discord = require('discord.js');
const Discord = require("discord.js");

class omchannel extends commando.Command
{
    constructor(client)
    {
            super(client,{
                name: "omca",
                description: "Sets the one time message channel.",
                memberName: "omca",
                group: "channel",
                usage: "d!omca CHANNELID",
                accesableby: "Moderators",
                aliases: ["oneadd", "onemessagechanneladdition"]
        });
    }

async run(message, args)
{
    if(!message.member.hasPermission(["MANAGE_CHANNELS", "MANAGE_ROLES"])) return message.channel.send("You don't have sufficent permissions to use this!")

    let role = message.guild.roles.find(role => role.id == args[0]) || message.mentions.roles.get(args[0])
    if(role) return message.channel.send("You did not specify a role ID. You can get a ID by doing backslash@ROLENAME (Make sure role is mentionable).")

    let channel = (channel => channel.id == args[1]) || message.channel.id(args[1])
    if(channel) return message.channel.send("You did not specify a channel ID. You can get one by going into Dev Mode, right click the channel in the sidebar, and press Copy ID.")

    if(message.guild.me.hasPermission(["MANAGE_ROLES", "ADMINISTRATOR"])) return message.channel.send("I don't have sufficent permissions! Give me them!")

    if(message.channel.id == args[0]) {
    let bannedRole = message.guild.roles.find(role => role.name === args[1])
    message.member.addRole(bannedRole)
        }
    }
}

module.exports = omchannel;

我基本上是将这段代码转换为用户可以自定义的代码。

doopliss.on('message', function(message) { {
if(message.channel.id == 'argument2') {
  let bannedRole = message.guild.roles.find(role => role.name === 'argument1');
      message.member.addRole(bannedRole);
  }
}})

我想使用角色ID,而不是使用角色名称。

期望:一个命令,您可以自定义哪个通道是一次性消息通道,然后获得一个分配的角色。

发生:Discord Bot有效,但无效。 (机器人功能正常,但提示错误)

0 个答案:

没有答案