我正试图让我的代码有理由踢人,而DM则说他们已被<server>
踢给<reason>
。目前没有发出任何理由。
看过在线教程,但没有运气。我也问过一些人,但他们也不知道。似乎没有多少人使用discord.js,任何帮助将不胜感激。 =)
Message Bot Sends Message I Sent
const Discord = require('discord.js');
const { token } = require('./config.json');
var { prefix, logchannel } = require('./config.json');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Bot loaded!');
client.user.setActivity('SUPPORT: !info', {
type: 'PLAYING'
});
})
client.on('message', message => {
if (message.content === `${prefix}ping`) {
message.channel.send('Pong.');
console.log(`COMMAND: ${message.member.displayName} issued ping command.`);
} else if (message.content === `${prefix}info`) {
message.channel.send(`This server's name is: ${message.guild.name}
It has ${message.guild.memberCount} total members.
It is running **WastefulBot** by **USER HIDDEN**
For support please join LINK HIDDEN`);
console.log(`COMMAND: ${message.member.displayName} issued info command.`);
} else if (message.content === `${prefix}help`) {
console.log(`COMMAND: ${message.member.displayName} issued help command.`);
message.delete();
message.channel.send('Please check your dm\'s.');
message.member.send(`__**WastefulBot Help**__
!ping | Pong.
!info | Returns information on the server and how to get support for the bot.
!donate | Get information on how to donate.
!help | Shows this information.
__**Administration Commands**__
(Please note these commands require corresponding permissions)
!kick <@user> | Kicks the specified user.
!ban <@user> | Bans the specified user.
__**Management Commands**__
(Please note these commands require corresponding permissions)
!staff | Grants a user staff. (WIP - May not work on most servers.)
`);
}
if (message.content === (`${prefix}setlog`)) {
if (message.member.hasPermission("MANAGE_CHANNEL")) {
message.channel.send('Sorry. This command is currently WIP.');
console.log(`WARNING: ${message.member.displayName} issued setlog command, this command is WIP and does not work.`);
}
}
if (message.content === (`${prefix}donate`)) {
message.channel.send('You can donate at ``https://www.patreon.com/wasteful_development``');
}
//KICK COMMAND STARTS HERE
else if (message.content.startsWith(`${prefix}kick`)) {
if (message.member.hasPermission("KICK_MEMBERS")) {
if (!message.mentions.users.size) {
return message.reply('You must tag 1 user.');
} else {
let member = message.mentions.members.first();
let reason = message.content.split(" ").slice(22);
if (member.kickable == false) {
message.channel.send("That user cannot be kicked!");
return;
} else {
member.send(`You have been kicked from \`\`${message.guild.name}\`\` for the reason ${reason}.`).then((message) => {
member.kick(reason).then((member) => {
message.channel.send(" " + member.displayName + " has been kicked!");
console.log(`KICK: ${message.member.displayName} successfully executed kick command.`);
});
});
}
}
} else {
message.channel.send("You do not have permission to use kick.");
return;
}
}
//End of kick mthd
else if (message.content.startsWith(`${prefix}staff`)) {
if (message.member.hasPermission("MANAGE_ROLES")) {
if (!message.mentions.users.size) {
return message.reply('You must tag 1 user.');
} else {
let member = message.mentions.members.first();
member.addRole("569174153337503804");
message.channel.send(`Granted ${member.displayName} staff!`);
message.channel.send(`Warning this command will not have worked on most servers as it is WIP.`);
console.log(`STAFF: ${message.member.displayName} successfully granted ${member.displayName} staff .`);
}
} else {
message.channel.send("**You do not have permission to grant users staff.**");
return;
}
}
});
client.login(token);
答案 0 :(得分:2)
看看您的错误,这是问题的时间表。
member.send(...)
被拒绝。.then()
不返回任何内容,而不是预期的message
参数。displayName
的{{1}}属性时,由于从未返回您的参数message.member
,它会引发错误。实施message
方法来处理被拒绝承诺的可能性。
请记住,您必须将函数声明为异步才能使用.catch()
:
await
然后,在您的命令中:
client.on('message', async message => { // ES6
答案 1 :(得分:1)
您的漫游器可能由于其隐私设置而无法被DM用户踢出。因为用户被踢了,所以他们不再与bot共享服务器(除非它是一个非常普遍使用的bot,这将增加用户使用该bot在多台服务器中的几率),这意味着该bot是无法向该用户发送DM的可能性很高。
答案 2 :(得分:-2)
您的代码中的错误是class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data: [],
library: null,
};
}
componentDidMount() {
fetch("/json.bc", {
method: "get"
})
.then(response => response.text())
.then(text => {
let Maindata = JSON.parse(text.replace(/\'/g, '"'));
this.setState(
state => ({
...state,
data: Maindata
}),
() => {
this.reorganiseLibrary();
}
);
})
.catch(error => console.error(error));
}
reorganiseLibrary = () => {
const { data } = this.state;
let library = data;
library = _.chunk(library);
this.setState({
library,
});
};
// handle per page
handlePerPage = evt =>
this.setState(
{
perPage: evt.target.value
},
() => this.reorganiseLibrary()
);
renderMinTotal = () => {
const { library } = this.state;
if (!library || (library && library.length === 0)) {
return "";
}
return library.reduce((acc, lib) => {
const libMin = Math.min(...lib.map(item => item.totalCom));
return acc === undefined ? libMin : libMin < acc ? libMin : acc;
}, undefined);
};
renderMaxTotal = () => {
const { library } = this.state;
if (!library || (library && library.length === 0)) {
return "";
}
return library.reduce((acc, lib) => {
const libMax = Math.max(...lib.map(item => item.totalCom));
return libMax > acc ? libMax : acc;
}, 0);
};
render() {
const { library } = this.state;
return (
<div>
<div>
<input
type="range"
min={this.renderMinTotal()}
max={this.renderMaxTotal()}
defaultValue={this.renderMaxTotal()}
step="1000"
className="multirange"
/>
</div>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById('Result'))
。您会看到member
和user
是两回事。
member.send()
仅适用于user
, so you should do member.user.send()
,并且可以使用。
另外,您将需要兑现该承诺,因此,如果该用户禁用了DM,则由于漫游器无法禁用该用户,因此bot无法对其进行DM处理。像这样:
.send()
请记住,await member.user.send(`You have been kicked!`)
.catch(() => message.channel.send("User seems to have DMs disabled!"));
await member.kick("reason")
.then(member => message.channel.send(`${member.displayName} has been kicked!`))
.catch(e => console.error(e.stack));
是another way在异步函数中链接await
的情况。