简体   繁体   English

Discord.js v13 为什么我的会员移动命令不起作用?

[英]Discord.js v13 Why is my member moving command not working?

I've made this command to "wake up" members by moving them 10 times between 2 voice channels.我已经通过在 2 个语音通道之间移动 10 次来“唤醒”成员。 It's supposed to work if you have the administrator permissions (will propably change that in the future tho) and if used incorrectly return the correct usage in an embed.如果您拥有管理员权限(将来可能会更改它),并且如果使用不当,则在嵌入中返回正确的用法,它应该可以工作。 Everything works EXCEPT for the actual moving of users and I can't for the life of me figure out how to move members.一切正常,除了用户的实际移动之外,我无法为我的生活弄清楚如何移动成员。 Any help?有什么帮助吗? My code:我的代码:

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

module.exports = {
    name: 'pobudka',
    description: "Budzi gracza.",
    execute(message, args)
    {
        const target = message.mentions.members.first()
        const usageEmbed = new MessageEmbed() //the embed sent if the usage is incorrect
            .setColor('ff0004')
            .setTitle('Poprawne użycie')
            .addField('rp pobudka @user', 'zamienić @user na wzmiankę użytkownika')

        if(message.member.permissions.has(Permissions.FLAGS.ADMINISTRATOR)) //checking if the invoking member has the administrator perms to use the command
        {
            if(target)
            {
                for(let i = 10; i > 0; i--) //loop for changing the voice channels 10 times 
                { 
                    message.guild.member(target.id).voice.setChannel("940573437561303080") //moving the member to a different voice channel
                    message.guild.member(target.id).voice.setChannel("946790140003631165") //moving the member to a different voice channel
                }
            }
            else
            {
                message.reply({ embeds: [usageEmbed]}) //sending the usage embed
            }
        }
        else
        {
            message.reply("Nie możesz tego użyć.") //replying if the invoking member doesnt have administrator perms
        }
    }
}

The error I'm getting:我得到的错误:

C:\Users\Miki\Desktop\dc bots\jajco bot smol\commands\pobudka.js:22
                    message.guild.member(target.id).voice.setChannel("940573437561303080")
                                  ^

TypeError: message.guild.member is not a function
    at Object.execute (C:\Users\Miki\Desktop\dc bots\jajco bot smol\commands\pobudka.js:22:35)
    at Client.<anonymous> (C:\Users\Miki\Desktop\dc bots\jajco bot smol\main.js:134:44)
    at Client.emit (node:events:520:28)
    at MessageCreateAction.handle (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\actions\MessageCreate.js:26:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Miki\Desktop\dc bots\jajco bot smol\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)

(and yes the response messages are in polish because this isn't just for me but for a small server which is, you guessed it - polish) (是的,响应消息是经过润色的,因为这不仅适用于我,而且适用于小型服务器,您猜对了 - 润色)

The reason it is erroring is because you need to look for the members from cache but as mentioned above, target is already a member object.它出错的原因是因为您需要从缓存中查找成员,但如上所述,目标已经是成员 object。

To find members you need to code it like this要查找成员,您需要像这样编写代码

message.guild.members.cache.get(target.id)

or like this或者像这样

message.guild.members.cache.find(member => member.id === target.id)

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

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