繁体   English   中英

公会未定义| discord.js

[英]guild not defined | discord.js

我有这个问题,说公会没有定义。 我对成员有同样的问题,但我通过添加一个常量来解决它。 我对 javascript 和 node.js 很陌生。 有人可以帮忙吗? 我什至尝试查看 index.js 并复制上面的常量,但没有成功。

const member = guild.member.first(message.author);
               ^

ReferenceError: guild is not defined
    at Object.<anonymous> (C:\bot1\commands\prune.js:7:16)
[90m    at Module._compile (internal/modules/cjs/loader.js:1138:30)[39m
[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)[39m
[90m    at Module.load (internal/modules/cjs/loader.js:986:32)[39m
[90m    at Function.Module._load (internal/modules/cjs/loader.js:879:14)[39m
[90m    at Module.require (internal/modules/cjs/loader.js:1026:19)[39m
[90m    at require (internal/modules/cjs/helpers.js:72:18)[39m
    at Object.<anonymous> (C:\bot1\index.js:11:18)
[90m    at Module._compile (internal/modules/cjs/loader.js:1138:30)[39m
[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)[39m
const Discord = require('discord.js');
const Client = new Discord.Client();

const client = new Discord.Client();
client.commands = new Discord.Collection();

const member = guild.member.first(message.author);
const { Permissions } = require('discord.js');

const permissions = new Permissions([
    'MANAGE_MESSAGES',
]);

module.exports = {
    name: 'prune',
    description: 'prune up to 99 messages.',
    execute(message, args) {
        const amount = parseInt(args[0]) + 1
    
        if (member.hasPermission('MANAGE_MESSAGES')) 
        {

            if (isNaN(amount)) {
                return message.channel.send('That\'s not a valid number');
            } else if (amount <= 1 || amount > 100) {
                return message.channel.send('You need to input a number between 1 and 99.');
            }

            message.channel.bulkDelete(amount, true).catch(err => {
            console.error(err);
            message.channel.send('There was an error trying to prune messages in this channel.');
        })

        if (!member.hasPermission('MANAGE_MESSAGES'))
        {
            message.channel.send("You dont have the required permissions to execute this command")
        }

        };
    }
};

您需要在execute() function 中定义member ,因为您需要从message中获取 GuildMember object

const Discord = require('discord.js');
const Client = new Discord.Client();

const client = new Discord.Client();
client.commands = new Discord.Collection();

const { Permissions } = require('discord.js');

const permissions = new Permissions([
    'MANAGE_MESSAGES',
]);

module.exports = {
    name: 'prune',
    description: 'prune up to 99 messages.',
    execute(message, args) {
        const member = message.member;
        const amount = parseInt(args[0]) + 1
    
        if (member.hasPermission('MANAGE_MESSAGES')) 
        {

            if (isNaN(amount)) {
                return message.channel.send('That\'s not a valid number');
            } else if (amount <= 1 || amount > 100) {
                return message.channel.send('You need to input a number between 1 and 99.');
            }

            message.channel.bulkDelete(amount, true).catch(err => {
            console.error(err);
            message.channel.send('There was an error trying to prune messages in this channel.');
        })

        if (!member.hasPermission('MANAGE_MESSAGES'))
        {
            message.channel.send("You dont have the required permissions to execute this command")
        }

        };
    }
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM