我想向我的机器人添加代码,当特定用户玩特定游戏(即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"
]
});
}
});
答案 0 :(得分:0)
尝试一下
if(GuildMember.username === 'Specific_Username_here')
if(GuildMember.presence.game === 'Specific_Game_here')
// do whatever here
如果您知道用户的特定ID字符串,也可以使用 GuildMember.id
。我尚未对此进行测试,而宁愿将此作为评论发布,但我尚未获得该许可。
答案 1 :(得分:0)
要将消息发送到特定频道,请使用以下方法:
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")
}
答案 2 :(得分:0)
所以我才知道。要弄清楚这一点,这是一段漫长的旅程。 这是代码:
// 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"
]
});
}
}
});
但是,我还需要解决一个问题: It says "null" when I close the application.
我该如何解决?