首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Eris直接调用用户

使用Eris直接调用用户
EN

Stack Overflow用户
提问于 2021-03-12 10:06:06
回答 1查看 49关注 0票数 0

我正在尝试用Eris制作一个机器人,我需要它能够在直接消息中呼叫人们。这就是我想出来的,但很明显,我遗漏了一些东西,因为它不起作用。

代码语言:javascript
复制
                        if (contacts[name].dm) {
                            const channel = await bot.getDMChannel(contacts[name].id)
                            await channel.ring([contacts[name].id])
                        }else{
                            bot.joinVoiceChannel(contacts[name].id)
                        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-30 00:13:29

这可能不是最有效或最干净的方式,但我做到了。

代码语言:javascript
复制
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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66593195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档