如何对我的discord机器人进行编码,以查找discord服务器中的成员数量并将其存储为变量。 其次,当某个事件(例如,如果消息中包含粗俗的单词)表示感谢时,我如何编码不和谐的bot来删除其他人的消息
答案 0 :(得分:0)
第一个:
let members = message.guild.members;
第二个,您应该使用RegEx:
if (message.content.match(/SwearWord/)) message.delete({ reason: "Swearword" });
您只需要调整Sregword RegEx。另外,下次请注意:请提供更多信息,例如一些代码,显示您已经尝试过的内容。
答案 1 :(得分:0)
要在行会中获得会员人数,您必须从memberCount
获得Guild
属性。 \ n
示例-
const memberCount = message.guild.memberCount
答案 2 :(得分:0)
您可以使用Guild
的{{3}}属性来查找它具有多少个成员。
memberCount
要检测脏话,可以使用includes()
函数。 .includes()
函数的工作方式示例:
// example message
const message = 'Hello World!'
if (message.includes('Hello'))
console.log('This message includes the word hello');
如果第一个字符串包括第二个给定的字符串,则此函数将返回true
。否则,它将返回false
。如果您只检测一个一个脏话,这本身就可以很好地工作,但是如果有多个发誓的话,这是一种更有效的方法。
// another example message
const message = 'My name is John. I like baking, dancing, and playing Mario.';
// now, create an array of every swear word you'd like to avoid
// make sure they're in lower case!
const array = ['baking', 'dancing', 'playing'];
var foundInText = false;
// here's the fun part. create a loop iterating through every element in your
// blacklisted word array
for (word of array) {
// if one of the words is included in the message,
// flip the `foundInText` variable to true!
if (message.toLowerCase().includes(word)) {
foundInText = true;
break; // break out of the loop, a word was found
};
};
// if a word was found...
if (foundInText) {
// you can do whatever you want here
// including deleting the message,
// sending a warning...
// whatever you want
console.log('This string has a blacklisted word');
};
答案 3 :(得分:0)
要获取服务器的会员数,.memberCount
属性将起作用
let membercount = message.guild.memberCount
要删除脏话,
if (message.toLowerCase().includes(`poop`) {
message.delete()
message.channel.send(`poop is a swear word`)
}