2017-04-08 4 views
-2

최근 불화 서버용 로봇을 만들었습니다. 이제 나는 그를 나쁜 말을 걸러 내고 싶다. 예를 들어discord bot (JavaScript)에 의한 단어 필터링

: (봇없이)


사용자 : 당신은 (봇 포함)


사용자 병신에게 있습니다 : 당신이이 [맹세 때문에 나는 바보 ]


이는 Discord에서도 가능합니까? 내 봇에게 모든 권한을주었습니다! (메시지 제거를 포함하여 프로그램 자체에서 메시지를 편집 할 수 없음)

그렇지 않으면^다음을 수행 할 수 있습니까?

직접 다음과 같은 메시지를 삭제 쓸 수있는 능력 :


봇 : @username 맹세하지 마십시오!


이제 다음 코드를 (I 유용 경우 몰라요) 한 :

const Discord = require('discord.js'); 
const client = new Discord.Client(); 

client.on('ready',() => { 
    console.log('Hello, the bot is online!') 
}); 

client.on('message', message => { 
    if(message.content === '--Trump'){ 
     message.reply('He is the president of the United States of 
America!'); 
    } 
    if(message.content === '--Putin'){ 
     message.reply('He is the president of Russia!'); 
    } 
}); 

client.login('MzAwMzM5NzAyMD*1NDUxNzc4.C8rH5w.M44LW*nrfbCR_zHzd**vtMqkr6nI'); 
+0

[문서 확인] (https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=edit)에 귀찮았습니까? –

+0

@ André Dion 아니, 링크 해 주셔서 감사합니다! 임 꽤 자바 스크립트에 새로운. 어떻게 그 코드를 사용합니까? –

+0

client.login() 행을 숨기십시오. 나는 사람들이 당신의 봇에 무작위로 접근하기를 바라지 않는다고 확신한다 ... – Arctiic

답변

0

시도 :

client.on('message', message => { 
    message.edit(message.content.replace(/asshole/gi, "[I'm stupid because I swear]")) 
     .then(msg => console.log(`Updated the content of a message from ${msg.author}`)) 
     .catch(console.error); 
}); 

신용 @ 앙드레 디온로에서 올바른 방법을 데리고 위해 API

+0

내가 '똥구멍'을 칠 때 나는 이것을 얻는다 : (노드 : 13676) UnhandledPromiseRejectionWarning : 처리되지 않은 약속 거부 (거부 ID : 1) : 오류 : 금지됨 –

+0

그리고 ';'앞에 ')'코드가 누락되었습니다. 비주얼 스튜디오는 말했다. –

+0

@ M.Kaçiran이 수정하여 API 문서에서 좀 더 약속 된 처리를 삽입했습니다. – xDreamCoding