0

我使用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); 我的服务器看起来像这样我的服务器带有频道名称和表情符号

我的完整代码是这样的 -

    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 {}
  }

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

4

2 回答 2

0

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

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

于 2019-09-29T20:37:02.160 回答
0

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

于 2019-09-30T06:33:15.360 回答