-
Notifications
You must be signed in to change notification settings - Fork 0
/
JapaneseName.js
64 lines (59 loc) · 1.92 KB
/
JapaneseName.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const { Client, Intents } = require("discord.js");
const intents = new Intents([
Intents.NON_PRIVILEGED,
"GUILD_MEMBERS",
]);
const config = require('./config.json')
const client = new Client({ ws: { intents } });
const wanakana = require('wanakana');
client.on('ready', () => {
console.log('Ready');
});
client.on('message', msg => {
if (msg.content === config.command) {
console.log('fetching');
FetchMembers(msg);
}
client.on('guildMemberAdd', member => {
Translate(member)
})
});
async function Translate(member) {
console.log(member.user.username)
if(member.roles.cache.some(r => r.name === config.safeRole)) {
console.log("Skipping "+member.user.username+" due to anti nick role")
} else {
const text = member.user.username.toString();
const jName = await translate(text, config.lang);
console.log('translated ' + member.user.username + ' to ' + jName);
member.setNickname(jName).catch(err => {
if (err) {
console.log(err);
}
})
if (jName === member.user.username) {
console.log('Setting alt name for ' + member);
const kName = wanakana.toKatakana(member.user.username, {useObsoleteKana: true})
member.setNickname(kName).catch(err => {
if (err) {
console.log(err);
}
})
} else {
console.log('success');
}
return;
}
return;
}
async function FetchMembers(msg) {
const Members = (await msg.guild.members.fetch()).array()
console.log('fetched ' + Members);
console.log(Members.length);
for (let i = 0; i < Members.length; i++) {
const Member = Members[i];
console.log('Translating' + Member.user.username);
Translate(Member);
}
}
client.login(config.botToken);