您可以为对特定表情符号做出反应的人添加角色吗?

时间:2021-06-29 18:41:46

标签: discord.js

我希望我的代码拥有它,以便它发送消息,人们用特定的表情符号做出反应,然后获得角色。否则假设为false,则无法获取角色。我在向人员添加角色时遇到问题,所以这是我的代码。 (Discord.js)

  if (message.content === 'sky exclusive') {
    message.channel.send('react to this message with a smiley face for an exclusive role!');
    message.react('?');
    if(message.react === '?') {
    guild.roles.create({
  data: {
    name: 'rolered',
    color: 'RED',
  },
  reason: 'we needed a role for rolered',
})
  .then(console.log)
  .catch(console.error);
  }
}
});

我的所有代码如下所示:

const Discord = require('discord.js');
const client = new Discord.Client();
client.login('REDACTED');
client.on('ready', () => {
  console.log('Sky connected to node.js servers');
 console.log('Console connected, logged in as $[client.user.tag}.');
});
client.on('message', msg => {
  if (message.content === 'sky claim') {
    message.channel.send('${message.author} claimed 250 SkyBucks. Spend SkyBucks on colored roles.');
    console.log('${message.author} executed command successfully');
  }
});
client.on('message', msg => {
  if (message.content === 'sky twitter') {
    message.channel.send('Our twitter channel is @RippinCardPacks, I will drop a link.');
    message.channel.send('https://twitter.com/rippincardpacks');
  }
});
client.on('message', msg => {
  if (message.content === 'sky eBay') {
    message.channel.send('Our eBay store is @CollectAmazing, I will drop a link:');
    message.channel.send('https://www.ebay.com/str/collectamazing');
  }
});
client.on('message', msg => {
  if (message.content === 'sky react') {
    message.channel.send('Reacting to your message with a little smiley face...');
    message.react('?');
  }
});
client.on('message', msg => {
  if (message.content === 'sky botcreator') {
    message.channel.send('@z4 made this bot');
  }
});
client.on('message', msg => {
if (message.content === 'sky socials') {
message.author.send("Hey! Just a quick reminder to check out our Twitter channel, and the eBay store.")
message.author.send("https://www.twitter.com/rippincardpacks")
message.author.send("https://www.ebay.com/sch/i.html?_nkw=collectamazing")
}
});
client.on('message', msg => {
  if (message.content === 'ping') {
    message.channel.send('pong');
  }
});

client.on('message', msg => {
  if (message.content === 'sky exclusive') {
    message.channel.send('react to this message with a smiley face for an exclusive role!');
    message.react('?');
    if(message.react === '?') {
    guild.roles.create({
  data: {
    name: 'rolered',
    color: 'RED',
  },
  reason: 'we needed a role for rolered',
})
  .then(console.log)
  .catch(console.error);
  }
}
});





1 个答案:

答案 0 :(得分:0)

<Message>.react 是一个函数。您可能正在寻找反应收集器或反应事件。

//Reaction collector
let collector = <Message>.createReactionCollector(r => r.emoji.name === '?');
collector.on('collect', async (reaction, user) => {
let guild = reaction.message.guild;
let member = guild.member(user);
member.roles.add('someRole')
})

您可能需要对此进行调整,我没有进行测试。