简体   繁体   English

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

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

I want to add a code to my bot where it will send a message when a specific user plays a specific game (ie Left 4 Dead 2).我想向我的机器人添加一个代码,当特定用户玩特定游戏(即 Left 4 Dead 2)时,它会发送一条消息。 How do I do that?我怎么做? I don't want any commands anymore.我不再想要任何命令了。

// 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"
      ]
    });
  }
});

Try this尝试这个

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

GuildMember.id could also be used if you know that user's specific id string.如果您知道该用户的特定 id 字符串,也可以使用GuildMember.id I haven't tested this myself and I'd have rather posted this as a comment, but I don't have that permission yet.我自己还没有测试过,我宁愿将其作为评论发布,但我还没有获得该许可。

To send a message to a specific channel, use this:要向特定频道发送消息,请使用以下命令:

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

or或者

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

Summing it up, your code should be something like this:总结一下,你的代码应该是这样的:

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")
}

So I just figured it out.所以我只是想通了。 It was a long journey to figuring this one out.弄清楚这一点是一个漫长的过程。 Here's the code:这是代码:

// 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"
                ]
            });
        }
    }
});

However, I need one more problem solved: It says "null" when I close the application.但是,我还需要解决一个问题:当我关闭应用程序时它显示“null”。

How do I fix this?我该如何解决?

暂无
暂无

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

相关问题 当提到特定用户时,如何让不和谐机器人发送消息? - How do i make a discord bot send a message when a specific user is mentioned? 如何让我的 discord 机器人仅在用户开始输入特定频道时发送消息? - How can I make my discord bot only send a message if a user starts typing in a specific channel? 如何让我的 discord 机器人通过回复池回复特定消息? - How do I make my discord bot reply to a specific message with reply from a pool of replies? 让我的不和谐机器人在特定时间发送消息 - Make my discord bot send message at specific hours 如何让我的 discord 机器人回复包含特定字母/字符的消息? - How can I make my discord bot reply to a message when it contains a specific letter/character? 使不和谐机器人发送消息特定通道 - make discord bot to send message specific channel 如何让我的机器人在特定频道中发送消息,然后在一段时间后将其删除 - How do I make my bot send a message in a specific channel then delete it after a period of time 如何使用 discord 机器人将消息发送到特定通道? - How to send message to a specific channel with discord bot? 如何制作一个不和谐的机器人,当他运行命令时会向用户发送特定代码? 有点像帐户生成器 - How can I make a discord bot that will message user a specific code when he runs a command? Kind of like an account generator 如何让我的不和谐机器人复制并发送每个用户写的消息? - How do I make my discord bot copy and message every user written message?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM