【发布时间】:2020-12-22 03:12:36
【问题描述】:
所以基本上简而言之,我在 discord 上制作了一个机器人,并且有几句话我需要审查。没问题,除了现在用户可以简单地使用非英文键盘上的字符,绕过审查员。有没有一种简单的方法可以获取任何字符串并将其内容转换为英文键盘字符?提前致谢!
【问题讨论】:
标签: javascript string discord discord.js bots
所以基本上简而言之,我在 discord 上制作了一个机器人,并且有几句话我需要审查。没问题,除了现在用户可以简单地使用非英文键盘上的字符,绕过审查员。有没有一种简单的方法可以获取任何字符串并将其内容转换为英文键盘字符?提前致谢!
【问题讨论】:
标签: javascript string discord discord.js bots
DiscordJS 似乎在 NodeJS 上运行 - 所以这就是我们可以做的。 这是网站上发布的示例代码,但我们可以将其用于您的项目。
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'swearword') {
msg.reply('naughty!');
}
});
client.login('token');
有了这段代码,您就可以使用像Google Translate API 这样的 API 来获取每个处理过的单词并将其传递给它,然后等待响应。
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// Imports the Google Cloud client library
const {Translate} = require('@google-cloud/translate').v2;
// Instantiates a client
const translate = new Translate({projectId});
async function quickStart() {
// The text to translate
const text = 'Hello, world!';
// The target language
const target = 'ru';
// Translates some text into Russian
const [translation] = await translate.translate(text, target);
console.log(`Text: ${text}`);
console.log(`Translation: ${translation}`);
}
quickStart();
如果您将翻译过程与 msg.content 结合起来,您应该会得到另一种语言的脏话。
这是一个例子(我还没有测试过,但可以尝试一下): 您将需要 Google API 帐户/密钥等。所以请阅读他们关于如何设置的说明。
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// Imports the Google Cloud client library
const {Translate} = require('@google-cloud/translate').v2;
// Instantiates a client
const translate = new Translate({projectId});
var translation = "";
client.on('message', msg => {
// Translate msg.content
// The target language (i think english is en, you need to check)
const target = 'en';
// Translates some text into English (i think)
translation = await translate.translate(msg.content, target);
if (translation === 'swearword') {
msg.reply('naughty!');
}
});
client.login('token');
【讨论】: