[英]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.