【问题标题】:Discord.js Create a channel when a user reacts to a messageDiscord.js 当用户对消息做出反应时创建一个频道
【发布时间】:2021-03-31 10:02:06
【问题描述】:

有人可以帮助我吗,我如何获得以下代码来创建一个频道,所有用户都使用相同的表情符号做出反应?

我正在努力使所有对相同战斗表情做出反应的用户都将被放入同一个频道,然后我将创建多个包含他们信息的嵌入。但是由于某种原因,我很笨,我不知道该怎么做。

很抱歉,如果这很简单,但我是编码新手,因此感谢您提供任何帮助,希望大家圣诞快乐。

Client.on("messageReactionAdd", async (reaction, user, message) => {
  if (reaction.message.partial) await reaction.message.fetch();

  if (user.Client) return;
  if (!reaction.message.guild) return;

  if (reaction.emoji.name === "????") {
    let member = await reaction.message.guild.members.cache.get(user.id);
    console.log(user);
  }
});

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    首先,您将了解如何创建文本频道。

    <guild object>.channels.create('Text', {
        type: 'text',
            permissionOverwrites: [{
                id: <guild object>.id,
                allow: ['VIEW_CHANNEL'],
            }]
    });
    

    从反应创建频道很容易。请参阅下面的示例。

    const Discord = require('discord.js'); //Define Discord
    const client = new Discord.Client(); //Define client
    
    client.on("messageReactionAdd", async (reaction, user, message) => { //Add an event listener
      if (reaction.message.partial) await reaction.message.fetch();
    
      if (user.id === client.user.id) return; //If the reaction was from the bot, return
      if (!reaction.message.guild) return; //If the reaction was not in a guild
    
      if (reaction.emoji.name === "?") {
        let guild = reaction.message.guild
        guild.channels.create('channelName', { //Creating the channel
            type: 'text', //Make sure the channel is type is text
            permissionOverwrites: [ //Set overwrites
                {
                    id: guild.id,
                    allow: ['VIEW_CHANNEL'],
                }]
            })
      }
    });
    

    【讨论】:

    • 非常感谢您,您是救生员。我一直在尝试这样做一个星期大声笑
    猜你喜欢
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 2018-04-03
    • 2021-01-04
    • 1970-01-01
    • 2021-06-24
    • 2021-05-14
    相关资源
    最近更新 更多