gpt4 book ai didi

javascript - 语言和字符转换为英文键盘

转载 作者:行者123 更新时间:2023-12-04 08:57:56 25 4
gpt4 key购买 nike

所以基本上简而言之,我正在制作一个不和谐的机器人,我需要审查一些词。没问题,除了现在用户可以简单地使用来自非英语键盘的字符,并绕过审查员。有没有一种简单的方法可以获取任何字符串并将其内容转换为英文键盘字符?提前致谢!

最佳答案

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。获取处理的每个单词并将其传递给它,然后等待响应。
这是 sample provided by Google :
/**
* 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 帐户/ key 等。所以请阅读他们关于如何设置的说明。
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');

关于javascript - 语言和字符转换为英文键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63714186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com