1

我基本上是在尝试将代码变成对用户友好的地方。基本上变成了一个命令。有两个命令,但我目前只处理一个。一次性消息通道。我想在其中添加一个频道,如果你在频道中发言一次,机器人会给你一个角色,禁止你在频道中发言。

命令是这样的

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。

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

发生:Discord Bot 工作,但不工作。(机器人功能正常,但说的是错误信息)

4

0 回答 0