A
A
Aziz Shaniyazov2021-06-23 08:29:19
JavaScript
Aziz Shaniyazov, 2021-06-23 08:29:19

How can I fix errors in the node.js code for a discord bot?

When the bot finds the *ban [participant] message, it gives the following error:

(node:11560) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
DICT_TYPE_CONVERT: Only dictionaries may be used in a DictType
    at RequestHandler.execute (F:\bot\node_modules\discord.js\src\rest\RequestHandler.js:154:13)  
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async RequestHandler.push (F:\bot\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
    at async Object.module.exports.run (F:\bot\commands\ban.js:11:5)


Here is the code itself:
module.exports.run = async (bot, message, args) => {
    if (!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send('Недостаточно прав на использование команды!')
    else if (!message.guild.me.hasPermission("BAN_MEMBERS")) return message.channel.send('У меня недостаточно прав!')

    let member = message.guild.member(message.mentions.users.first() || message.guild.members.cache.find(m => m.user.username == args[0] || m.id == args[0]))
    if (!member) return message.channel.send('Укажите существующего пользователя')
    else if (member.hasPermission("BAN_MEMBERS")) return message.channel.send('Я не могу исключить этого пользователя')

    let reason = args.slice(1).join(' ') || 'Не указана'

    await member.ban(reason)
    await message.channel.send(`<@${message.author.id}> исключил <@${member.id}>\n**Причина**: ${reason}`)
}

module.exports.help = {
    name: 'ban'
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-06-23
@Aziz25

- member.ban(reason)
+ member.ban({ reason: `${reason}` })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question