使用 Eris 直接调用用户
Call a user directly using Eris
我正在尝试用 Eris 制作一个机器人,我需要它能够通过直接消息呼叫人们。这是我想出的,但很明显,我遗漏了一些东西,因为它不起作用。
if (contacts[name].dm) {
const channel = await bot.getDMChannel(contacts[name].id)
await channel.ring([contacts[name].id])
}else{
bot.joinVoiceChannel(contacts[name].id)
}
可能不是最有效或最干净的方法,但我做到了。
function discordAPI(authToken,apiEndpoint,JSONparams,type="GET") {
var xhr=new XMLHttpRequest()
console.log("Connecting to https://discord.com/api/v9"+apiEndpoint)
xhr.open(type,"https://discord.com/api/v9"+apiEndpoint,true)
xhr.setRequestHeader('Content-Type','application/json')
xhr.setRequestHeader('Authorization',authToken)
console.log(authToken)
xhr.onload = function () {
console.log('DONE: ', xhr.status);
console.log('REPONSE: ', xhr.reponseText);
// console.log('=======================');
// console.log('REPONSE_HEADERS:\n', xhr.getAllResponseHeaders());
// console.log('=======================')
};
xhr.send(JSON.stringify(JSONparams))
}
//...
const channel = await bot.getDMChannel(id)
await sleep(time*1000)
discordAPI(bot.token, ('/channels/' + channel.id + '/call/ring'), '', 'POST')
bot.joinVoiceChannel(channel.id).then((vconnect) => { //THIS IS NECESSARY TO JOIN THE CALL!!
console.log(vconnect)
if(sf!='null'){vconnect.play(__dirname + "/../sfx/" + sf + ".mp3")}
vconnect.once("userDisconnect", () => { if(userID == id){bot.switchChannel(null)} });
vconnect.once("end", () => { bot.switchChannel(null) });
vconnect.once("error", () => { console.log("----\n"+Error.toString()+"----\n") });
})
await sleep(timespent*60*1000)
bot.disconnect()
console.log('Called.')
bot.connect()
我正在尝试用 Eris 制作一个机器人,我需要它能够通过直接消息呼叫人们。这是我想出的,但很明显,我遗漏了一些东西,因为它不起作用。
if (contacts[name].dm) {
const channel = await bot.getDMChannel(contacts[name].id)
await channel.ring([contacts[name].id])
}else{
bot.joinVoiceChannel(contacts[name].id)
}
可能不是最有效或最干净的方法,但我做到了。
function discordAPI(authToken,apiEndpoint,JSONparams,type="GET") {
var xhr=new XMLHttpRequest()
console.log("Connecting to https://discord.com/api/v9"+apiEndpoint)
xhr.open(type,"https://discord.com/api/v9"+apiEndpoint,true)
xhr.setRequestHeader('Content-Type','application/json')
xhr.setRequestHeader('Authorization',authToken)
console.log(authToken)
xhr.onload = function () {
console.log('DONE: ', xhr.status);
console.log('REPONSE: ', xhr.reponseText);
// console.log('=======================');
// console.log('REPONSE_HEADERS:\n', xhr.getAllResponseHeaders());
// console.log('=======================')
};
xhr.send(JSON.stringify(JSONparams))
}
//...
const channel = await bot.getDMChannel(id)
await sleep(time*1000)
discordAPI(bot.token, ('/channels/' + channel.id + '/call/ring'), '', 'POST')
bot.joinVoiceChannel(channel.id).then((vconnect) => { //THIS IS NECESSARY TO JOIN THE CALL!!
console.log(vconnect)
if(sf!='null'){vconnect.play(__dirname + "/../sfx/" + sf + ".mp3")}
vconnect.once("userDisconnect", () => { if(userID == id){bot.switchChannel(null)} });
vconnect.once("end", () => { bot.switchChannel(null) });
vconnect.once("error", () => { console.log("----\n"+Error.toString()+"----\n") });
})
await sleep(timespent*60*1000)
bot.disconnect()
console.log('Called.')
bot.connect()