简体   繁体   中英

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. 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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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