繁体   English   中英

当特定用户玩特定游戏时,如何让我的不和谐机器人发送消息?

[英]How do I make my discord bot send a message when a specific user plays a specific game?

我想向我的机器人添加一个代码,当特定用户玩特定游戏(即 Left 4 Dead 2)时,它会发送一条消息。 我怎么做? 我不再想要任何命令了。

// Game Art Sender //
if (message.channel.id === '573671522116304901') {
  if (msg.includes('!L4D2')) { // THIS is what I want to change.
    message.channel.send('***[MATURE CONTENT]*** **Joining Game:**', {
      files: [
        "https://cdn.discordapp.com/attachments/573671522116304901/573676850920947733/SPOILER_l4d2.png"
      ]
    });
  }
});

尝试这个

if(GuildMember.username === 'Specific_Username_here')
    if(GuildMember.presence.game === 'Specific_Game_here')
        // do whatever here

如果您知道该用户的特定 id 字符串,也可以使用GuildMember.id 我自己还没有测试过,我宁愿将其作为评论发布,但我还没有获得该许可。

要向特定频道发送消息,请使用以下命令:

const channel = message.guild.channels.find(ch => ch.name === 'CHANNEL_NAME_GOES_HERE')
channel.send("MESSAGE GOES HERE")

或者

const channel = message.guild.channels.find(ch => ch.name === 'CHANNEL_NAME_GOES_HERE')
channel.send(VARIABLE_GOES_HERE)

总结一下,你的代码应该是这样的:

if(GuildMember.username === 'Specific_Username_here')
    if(GuildMember.presence.game === 'Specific_Game_here') {
        const channel = message.guild.channels.find(ch => ch.name === 'CHANNEL_NAME_GOES_HERE)
        channel.send("MESSAGE GOES HERE")
}

所以我只是想通了。 弄清楚这一点是一个漫长的过程。 这是代码:

// Game Detector \\
client.on("presenceUpdate", (oldMember, newMember) => {
if(newMember.id === '406742915352756235') {
    if(newMember.presence.game.name === 'ROBLOX') { // New Example: ROBLOX
        console.log('ROBLOX detected!');
        client.channels.get('573671522116304901').send('**Joining Game:**', {
            files: [
                "https://cdn.discordapp.com/attachments/567519197052272692/579177282283896842/rblx1.png"
                ]
            });
        }
    }
});

但是,我还需要解决一个问题:当我关闭应用程序时它显示“null”。

我该如何解决?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM