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

问题描述 投票:1回答:2

i使用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 {}
  }

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

node.js discord.js commando
2个回答
0
投票

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

String.includes()

0
投票

您可以将const channelName = '📜welcome📜'; console.log(channelName.includes('welcome'));与'554141970130403338'通道ID一起使用。

© www.soinside.com 2019 - 2024. All rights reserved.