简体   繁体   English

使用斜杠命令中的选项使用 discord.js DM 特定用户

[英]DM a specific user with discord.js with options in a slash command

today i was trying to make a /warn command that DM the warned user, but when i do that i see an error saying: "Expected token to be set for this request, but none was present" could anyone help me?今天我试图发出一个 /warn 命令,让 DM 警告用户,但是当我这样做时,我看到一条错误消息:“为此请求设置预期的令牌,但不存在”任何人都可以帮助我吗?

there is my code:有我的代码:

const { SlashCommandBuilder, PermissionFlagsBits, messageLink, Client } = require('discord.js');
const { GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });


module.exports = {
    data: new SlashCommandBuilder()
        .setName('warn')
        .setDescription('Choisi une qqun à warn.')
        .addUserOption(option =>
            option
                .setName('cible')
                .setDescription('Le membre à warn')
                .setRequired(true))
        .addStringOption(option =>
            option
                .setName('raison')
                .setDescription('La raison du warn'))
        .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
        .setDMPermission(false),
        async execute(interaction) {
            const target = interaction.options.getUser('cible');
            
            await client.users.send(target.id, 'vous avez été warn.')
            await interaction.reply(`${target.username} warn`);
        },
};

you just need to do你只需要做

let raison = interaction.options.getString('raison');
if (!raison) raison = "No raison provided.";
try { 
target.send(`vous avez été warn. \n> Raison: ${raison}`)
} catch (e) { interaction.reply({content: 'couldn\'t dm user his DMs are closed', ephemeral: true}) } 

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

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