如何按名称查找包含表情符号Discord的频道?

时间:2019-09-29 15:21:02

标签: node.js discord.js commando

我使用const channel = member.guild.channels.find(ch => ch.name === `welcome`);代码获取简单的频道名称,表示欢迎,但是当同一频道包含表情符号?welcome?时 如何找到表情符号?welcome?或其他表情符号内的任何频道。

const channel = member.guild.channels.find(ch => ch.name === `welcome`); // some code here channel.send(`See you once again ${member}!`, attachment);

类似的东西,但我尝试不起作用

const channel = member.guild.channels.find(ch => ch.name === ?welcome?); 我的服务器看起来像这样my server with channel name and emojis

我完整的代码是这样的-

    const channel = member.guild.channels.find(ch => ch.name === `welcome`);
    if (!channel) return;
    const canvas = Canvas.createCanvas(700, 250);
    const ctx = canvas.getContext('2d');

    const background = await Canvas.loadImage('./wallpaper.jpg');
    ctx.drawImage(background, 0, 0, canvas.width, canvas.height);

    ctx.strokeStyle = '#74037b';
    ctx.strokeRect(0, 0, canvas.width, canvas.height);

    // Slightly smaller text placed above the member's display name
    ctx.font = '28px sans-serif';
    ctx.fillStyle = '#ffffff';
    ctx.fillText('Welcome to the server,', canvas.width / 2.5, canvas.height / 3.5);

    // Add an exclamation point here and below
    ctx.font = applyText(canvas, `${member.displayName}!`);
    ctx.fillStyle = '#ffffff';
    ctx.fillText(`${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);

    ctx.beginPath();
    ctx.arc(125, 125, 100, 0, Math.PI * 2, true);
    ctx.closePath();
    ctx.clip();

    const avatar = await Canvas.loadImage(member.user.displayAvatarURL);
    ctx.drawImage(avatar, 25, 25, 200, 200);

    const attachment = new Discord.Attachment(canvas.toBuffer(), 'welcome-image.png');

    channel.send(`Welcome to the server, ${member}!`, attachment);

让我说我需要找到水平通道,如上图所示,表情符号会更改,但名称在那里,所以我该怎么做 这是我要添加的数据 编辑 名称是受欢迎的,但是当我添加表情符号时,名称会更改

'554141970130403338' => TextChannel {
    type: 'text',
    deleted: false,
    id: '554141970130403338',
     name: '📜welcome📜',
    position: 0,
    parentID: '566212268208029697',
    permissionOverwrites: Collection [Map] {
      '159985870458322944' => [PermissionOverwrites],
      '417208237142573056' => [PermissionOverwrites],
      '487733104652582920' => [PermissionOverwrites]
    },
    topic: '',
    nsfw: false,
    lastMessageID: '628112146806472715',
    lastPinTimestamp: null,
    rateLimitPerUser: 0,
    guild: Guild {
      members: [Collection [Map]],
      channels: [Circular],
      roles: [Collection [Map]],
      presences: [Collection [Map]],
      deleted: false,
      available: true,
      id: '417208237142573056',
      name: 'ETHYT Gaming',
      icon: '081568475c94dd5724dafc2547a0261c',
      splash: null,
      region: 'india',
      memberCount: 86,
      large: false,
      features: [],
      applicationID: null,
      afkTimeout: 3600,
      afkChannelID: '440842028713115648',
      systemChannelID: null,
      embedEnabled: undefined,
      verificationLevel: 0,
      explicitContentFilter: 0,
      mfaLevel: 0,
      joinedTimestamp: 1557471391163,
      defaultMessageNotifications: 'ALL',
      ownerID: '348832732647784460',
      _rawVoiceStates: [Collection [Map]],
      emojis: [Collection [Map]]
    },
    messages: Collection [Map] { '628112146806472715' => [Message] },
    _typing: Map {}
  }

当我在记事本中得到输出时,我可以看到写的欢迎词,但是它之前和之后是什么?

2 个答案:

答案 0 :(得分:0)

String.includes()将对您很有用。而不是比较整个字符串,它会在其中的任何位置搜索子字符串。

const channelName = '?welcome?';
console.log(channelName.includes('welcome'));

答案 1 :(得分:0)

您可以将const channel = member.guild.channels.get('554141970130403338');与通道ID“ 554141970130403338”一起使用。