How to use awaitReactions in guildMemberAdd(如何在 guildMemberAdd 中使用 awaitReactions)
问题描述
我在用户连接到我的服务器时向他们发送消息,我想通过点击反应继续授权.
我怎样才能创建这个?我正在使用以下代码:
I send messages to users when they connect to my server, and I want to continue authorization by clicking on reactions.
How can I create this? I'm using the following code:
robot.on("guildMemberAdd", (gMembAdd) =>
{
gMembAdd.send(`Hi ${gMembAdd.toString()} welcome to the server Test`).then(msg => {
msg.react('✅')
.then(() => msg.react('❎'));
//--------------------Developmend-------------------------------------
let filter = (reaction, user) => reaction.emoji.name === '✅' || reaction.emoji.name === '❎';
let col = msg.createReactionCollector(filter);
col.on('collect', r =>
{
if (r.users.last().id !== msg.author.id)
{
gMembAdd.addRole(gMembAdd.guild.roles.find("name", "Autorize")).catch(console.error)
r.remove(r.users.last().id);
console.log(` ${gMembAdd.user.id} и ${gMembAdd.user.username} and ${r.emoji}`);
}
});
//--------------------------------------------------------------------
});
如果反应是肯定的,我需要进行反应检查和角色分配,否则就踢.我不明白如何继续.
I need a reaction check and role assignment if the response is positive and kick if not. I don't understand how to continue.
这段代码会正确使用吗?
Will this code be used correctly?
推荐答案
要检查反应,您可以使用 MesssageReaction.emoji.name,就像你在上面所做的那样.
对于另一件事,您可以使用 GuildMember.addRole() &GuildMember.kick().
以下是您可以查看的示例:
To check the reaction you can use MesssageReaction.emoji.name, as you did above.
For the other thing, you can use GuildMember.addRole() & GuildMember.kick().
Here's a sample you can check out:
robot.on('guildMemberAdd', async member => {
let msg = await member.send(`Hi ${member} welcome to the server Test`);
await msg.react('✅');
await msg.react('❎');
msg.createReactionCollection(r => ['✅', '❎'].includes(r.emoji.name))
.on('collect', r => {
if (r.emoji.name == '✅')
member.addRole(member.guild.roles.find("name", "Authorize"))
.then(() => { console.log(`Added ${member.user.username} (${member.id}).`); })
.catch(console.error);
else if (r.emoji.name == '❎') member.kick("You got rejected.");
r.remove(r.users.last());
});
});
您还可以使用 消息.awaitReactions(),这样比较好,因为加了reaction之后就不继续了:
You can also use Message.awaitReactions(), which is better because it doesn't go on after the reaction is added:
robot.on('guildMemberAdd', async member => {
let msg = await member.send(`Hi ${member} welcome to the server Test`);
await msg.react('✅');
await msg.react('❎');
msg.awaitReactions(r => ['✅', '❎'].includes(r.emoji.name), {max: 1})
.then(collected => {
let r = collected.first();
if (r.emoji.name == '✅')
member.addRole(member.guild.roles.find("name", "Authorize"))
.then(() => { console.log(`Added ${member.user.username} (${member.id}).`); })
.catch(console.error);
else if (r.emoji.name == '❎') member.kick("You got rejected.");
r.remove(r.users.last())
});
});
这篇关于如何在 guildMemberAdd 中使用 awaitReactions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 guildMemberAdd 中使用 awaitReactions
基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
