admin管理员组

文章数量:1426347

I'm trying to make this bot able to do this...

  • Display User Roles
  • You do d!au @User and their user info shows

The only thing is that I do not know how to do this, I've found some other stack overflow questions but their bot requires "moment" and I have no idea what moment is. This is in a mand file, not a index.js file FYI.

    var mando = require('discord.js-mando');
var discord = require('discord.js');

class aboutuser extends mando.Command 
{
    constructor(client) {
        super(client, {
            name: 'aboutuser',
            group: 'help',
            memberName: 'aboutuser',
            description: 'Lists information about a specific user.',
            aliases: ['au', 'aboutu', 'auser', 'user'],
        })
    }
async run(message, args){

    let userinfo = {};
    userinfo.bot = message.client.user.bot;
    userinfo.createdat = message.client.user.createdAt;
    userinfo.discrim = message.client.user.discriminator;
    userinfo.id = message.client.user.id;
    userinfo.mfa = message.client.user.mfaEnabled;
    userinfo.pre = message.client.user.premium;
    userinfo.presen = message.client.user.presence;
    userinfo.tag = message.client.user.tag;
    userinfo.uname = message.client.user.username;
    userinfo.verified = message.client.user.verified;

    userinfo.avatar = message.client.user.avatarURL;

    var myInfo = new discord.RichEmbed()
        .setAuthor(userinfo.uname, userinfo.avatar)
        .addField("Bot?",userinfo.bot, true)
        .addField("Created At",userinfo.createdat, true)
        .addField("Discriminator",userinfo.discrim, true)
        .addField("Client ID",userinfo.id, true)
        .addField("2FA/MFA Enabled?",userinfo.mfa, true)
        .addField("Paid Account?",userinfo.pre, true)
        .addField("Presence",userinfo.presen, true)
        .addField("Client Tag",userinfo.tag, true)
        .addField("Username",userinfo.uname, true)
        .addField("Verified?",userinfo.verified, true)
        .setColor(0xf0e5da)
        .setFooter('s!aboutserver')
        .setTitle("About this user...")
        .setThumbnail(userinfo.avatar)


        message.channel.sendEmbed(myInfo);

}

}
module.exports = aboutuser;

I want to make my bot able to display a user's roles and make it so that you can tag them.

Reality : The mand results in a error, but the bot is online. Referance Error, blank is not defined.

Expects : A bot that can list the roles of a user, and you can see the information of other users when using the mand.

I've only pasted the code that WORKS, not the ones that end up as failiures.

I'm trying to make this bot able to do this...

  • Display User Roles
  • You do d!au @User and their user info shows

The only thing is that I do not know how to do this, I've found some other stack overflow questions but their bot requires "moment" and I have no idea what moment is. This is in a mand file, not a index.js file FYI.

    var mando = require('discord.js-mando');
var discord = require('discord.js');

class aboutuser extends mando.Command 
{
    constructor(client) {
        super(client, {
            name: 'aboutuser',
            group: 'help',
            memberName: 'aboutuser',
            description: 'Lists information about a specific user.',
            aliases: ['au', 'aboutu', 'auser', 'user'],
        })
    }
async run(message, args){

    let userinfo = {};
    userinfo.bot = message.client.user.bot;
    userinfo.createdat = message.client.user.createdAt;
    userinfo.discrim = message.client.user.discriminator;
    userinfo.id = message.client.user.id;
    userinfo.mfa = message.client.user.mfaEnabled;
    userinfo.pre = message.client.user.premium;
    userinfo.presen = message.client.user.presence;
    userinfo.tag = message.client.user.tag;
    userinfo.uname = message.client.user.username;
    userinfo.verified = message.client.user.verified;

    userinfo.avatar = message.client.user.avatarURL;

    var myInfo = new discord.RichEmbed()
        .setAuthor(userinfo.uname, userinfo.avatar)
        .addField("Bot?",userinfo.bot, true)
        .addField("Created At",userinfo.createdat, true)
        .addField("Discriminator",userinfo.discrim, true)
        .addField("Client ID",userinfo.id, true)
        .addField("2FA/MFA Enabled?",userinfo.mfa, true)
        .addField("Paid Account?",userinfo.pre, true)
        .addField("Presence",userinfo.presen, true)
        .addField("Client Tag",userinfo.tag, true)
        .addField("Username",userinfo.uname, true)
        .addField("Verified?",userinfo.verified, true)
        .setColor(0xf0e5da)
        .setFooter('s!aboutserver')
        .setTitle("About this user...")
        .setThumbnail(userinfo.avatar)


        message.channel.sendEmbed(myInfo);

}

}
module.exports = aboutuser;

I want to make my bot able to display a user's roles and make it so that you can tag them.

Reality : The mand results in a error, but the bot is online. Referance Error, blank is not defined.

Expects : A bot that can list the roles of a user, and you can see the information of other users when using the mand.

I've only pasted the code that WORKS, not the ones that end up as failiures.

Share Improve this question asked Mar 12, 2019 at 7:24 SomePersonSomePerson 1,3095 gold badges19 silver badges48 bronze badges 1
  • 1 You should include the code that is giving you errors as then it can be reproduced or someone can look at it and tell you why it is giving an error. – Pentium1080Ti Commented Mar 12, 2019 at 7:28
Add a ment  | 

2 Answers 2

Reset to default 2

The following code should do all the stuff you want:

var mando = require('discord.js-mando');
var discord = require('discord.js');

class aboutuser extends mando.Command 
{
    constructor(client) {
        super(client, {
            name: 'aboutuser',
            group: 'help',
            memberName: 'aboutuser',
            description: 'Lists information about a specific user.',
            aliases: ['au', 'aboutu', 'auser', 'user'],
        })
    }
async run(message, args){
    const userMention = message.mentions.users.first() || msg.author;
    const memberMention = message.mentions.members.first() || msg.member;

    let userinfo = {};
    userinfo.bot = userMention.bot;
    userinfo.createdat = userMention.createdAt;
    userinfo.discrim = userMention.discriminator;
    userinfo.id = userMention.id;
    userinfo.mfa = userMention.mfaEnabled;
    userinfo.pre = userMention.premium;
    userinfo.presen = userMention.presence;
    userinfo.tag = userMention.tag;
    userinfo.uname = userMention.username;
    userinfo.verified = userMention.verified;

    userinfo.avatar = userMention.avatarURL;

    const rolesOfTheMember = memberMention.roles.filter(r => r.name !== '@everyone').map(role => role.name).join(', ')

    var myInfo = new discord.RichEmbed()
        .setAuthor(userinfo.uname, userinfo.avatar)
        .addField("Bot?",userinfo.bot, true)
        .addField("Created At",userinfo.createdat, true)
        .addField("Discriminator",userinfo.discrim, true)
        .addField("Client ID",userinfo.id, true)
        .addField("2FA/MFA Enabled?",userinfo.mfa, true)
        .addField("Paid Account?",userinfo.pre, true)
        .addField("Presence",userinfo.presen, true)
        .addField("Client Tag",userinfo.tag, true)
        .addField("Username",userinfo.uname, true)
        .addField("Verified?",userinfo.verified, true)
        .setColor(0xf0e5da)
        .setFooter('s!aboutserver')
        .setTitle("About this user...")
        .setThumbnail(userinfo.avatar)


        message.channel.sendEmbed(myInfo);

}

}
module.exports = aboutuser;

I added two new variables that check if there was a mention of a guildMember or not. If yes, the mand shows the stats of the mentioned member, if not, the bot shows the stats of the message author.

Then I added also a new variable "rolesOfTheMember" which is a list of all roles that the member owns. You can simply add this variable in your Discord RichEmbed and then list the roles that the guildMember has on the Discord server!

Have fun!

Moment is a package that allows you (pretty) easy time formating. You install it same as discord.js, so in your mand prompt you do npm install moment (if you installed discord.js using some other syntax, use the same one here too, just replace discord.js with moment). That will install the package and then you can use it, just don't forget to put const moment = require('moment'); to the beginning of your code and you should be good.

All of the time formating can be found here: https://momentjs./docs/#/parsing/string-format/

本文标签: javascriptDiscordJS Userinfo commandStack Overflow