在discord.js中执行禁令之前,如何对用户进行dm?
有人能告诉我如何在用户被禁止之前向他发送dm吗?一切都很好,但是dm。看起来,如果我把dm代码放在现在的位置,用户首先会被禁止,然后会收到一条直接消息,这显然不起作用,因为机器人和用户不共享服务器。 我的代码: 尝试使用,使其仅在在discord.js中执行禁令之前,如何对用户进行dm?,discord,discord.js,bots,dm,Discord,Discord.js,Bots,Dm,有人能告诉我如何在用户被禁止之前向他发送dm吗?一切都很好,但是dm。看起来,如果我把dm代码放在现在的位置,用户首先会被禁止,然后会收到一条直接消息,这显然不起作用,因为机器人和用户不共享服务器。 我的代码: 尝试使用,使其仅在message.channel.send()事件完成后才发生禁止 const{DiscordAPIError}=require(“discord.js”); const Discord=require('Discord.js'); const client=new Di
message.channel.send()事件完成后才发生禁止
const{DiscordAPIError}=require(“discord.js”);
const Discord=require('Discord.js');
const client=new Discord.client();
module.exports={
名称:"禁令",,
description:“允许您禁止服务器中的成员!”,
执行(消息,参数){
const member=message.indications.users.first();
const notBanYourself=new Discord.MessageEmbed()
.setColor(“ff0000”)
.setTitle(“禁令”)
.setDescription(“您不能禁止自己!”)
.setFooter(message.author.username)
.setTimestamp()文件
if(member.id==message.author.id)返回message.channel.send(notBanYourself);
if(message.member.permissions.has(“禁止成员”)| | message.member.permissions.has(“管理员”)){
const memberTarget=message.guild.members.cache.get(member.id);
const ban_dm=new Discord.MessageEmbed()
.setColor(“ff0000”)
.setTitle(“禁令”)
.setDescription(“您被“+message.author.username”禁止进入“+message.guild.name+”服务器)
.setFooter(message.author.username)
.setTimestamp()文件
memberTarget.send(ban_dm).然后(()=>{
国际单项体育联合会(成员){
ban({天:3,原因:args.slice(1.join)(“”});
const banked=new Discord.MessageEmbed()
.setColor(“ff0000”)
.setTitle(“禁令”)
.setDescription(“已成功禁止用户访问服务器。”)
.setFooter(message.author.username)
.setTimestamp()文件
message.channel.send(禁止);
}否则{
const notbanked=new Discord.MessageEmbed()
.setColor(“ff0000”)
.setTitle(“禁令”)
.setDescription(“出现错误:您需要提及要禁止的用户!\n如果这样做,您可能没有禁止用户的权限。”)
.setFooter(message.author.username)
.setTimestamp()文件
message.channel.send(不禁止);
}
});
}
}
}
const { DiscordAPIError } = require("discord.js");
const Discord = require('discord.js');
const client = new Discord.Client();
module.exports = {
name: 'ban',
description: "Allows you to ban a member from the server!",
execute(message, args) {
const member = message.mentions.users.first();
const notBanYourself = new Discord.MessageEmbed()
.setColor("#ff0000")
.setTitle("Ban")
.setDescription("You cannot ban yourself!")
.setFooter(message.author.username)
.setTimestamp()
;
if(member.id === message.author.id) return message.channel.send(notBanYourself);
if(message.member.permissions.has("BAN_MEMBERS") || message.member.permissions.has("ADMINISTRATOR")){
const memberTarget = message.guild.members.cache.get(member.id);
const ban_dm = new Discord.MessageEmbed()
.setColor("#ff0000")
.setTitle("Ban")
.setDescription("You got banned from the " + message.guild.name + " Server by " + message.author.username)
.setFooter(message.author.username)
.setTimestamp()
;
memberTarget.send(ban_dm)
if(member) {
memberTarget.ban({ days: 3, reason: args.slice(1).join(" ") });
const banned = new Discord.MessageEmbed()
.setColor("#ff0000")
.setTitle("Ban")
.setDescription("User has been banned from the server successfully.")
.setFooter(message.author.username)
.setTimestamp()
;
message.channel.send(banned)
}
else {
const notBanned = new Discord.MessageEmbed()
.setColor("#ff0000")
.setTitle("Ban")
.setDescription("There was an error: You need to mention the user, which you want to ban! \n If you did that, you probably do not have the permission to ban users.")
.setFooter(message.author.username)
.setTimestamp()
;
message.channel.send(notBanned)
}
}
}}