English 中文(简体)
差异14 在张贴新版面时,在通知频道张贴电文。
原标题:Discord.js 14 Ffor media channels - When new thread is posted, post a message in anoter channel

I have several media channels within my Discord. Each based around different topics. I m trying to get it to where if a new post is made in a media channel then a text channel gets a message sent into it with a link to the new media.

每一媒体频道也将有自己的信号频道。

这里是未遂文字:

const gameMediaMap = new Map();
gameMediaMap.set( 1236005955464986745 ,  1234209500437680260 );

client.on( messageCreate , async (message) => {
    if (gameMediaMap.has(message.channel.id)) {
        const gameNotifierChannelId = gameMediaMap.get(message.channel.id);
        const gameNotifierChannel = await client.channels.fetch(gameNotifierChannelId);

        if (gameNotifierChannel) {
            const postTags = message.content.match(/#[w-]+/g) || []; // Extract hashtags
            const postTagsString = postTags.join( ,  );

            const messageUrl = `https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.id}`;
            const notificationMessage = `A new clip was posted in <#${message.channel.id}>. [Go to clip](${messageUrl}).
Video tagged with:  ${postTagsString} .`;

            gameNotifierChannel.send(notificationMessage);
        }
    }
});

As it is nothing happens when a new post is made, but the rest of the bot this is attached to works flawlessly.

任何建议或想法?

问题回答

找到了解决办法。 需要使用校对而不是电线

// Mapping of game media channels to their corresponding notifier channels
const gameMediaMap = new Map([ // Media, Notification
    [ 1236006027955146792 ,  1134296339790970922 ], // 7 Days to Die
    [ 1157136842047623169 ,  1135347403046801480 ], // Battlebit Remastered
    [ 1158427246319648879 ,  1158292907153969152 ], // Battlefield 4
    [ 1236006184293630044 ,  1178481743309836328 ], // Call of Duty
    [ 1236006284562665573 ,  1232691826352324618 ], // Escape from Tarkov
    [ 1236007603839172658 ,  1197342057711276032 ], // Farming Simulator 22
    [ 1236005955464986745 ,  1234209500437680260 ], // Gray Zone Warfare
    [ 1236006450996711537 ,  12335729887425373690 ], // Ground Branch
    [ 1236006385272225823 ,  1234212407551983727 ], // Helldivers 2
    [ 1236006511092695080 ,  1135347218296098867 ] // Minecraft
]);

client.on( threadCreate , async thread => {
    if (thread.parentId && gameMediaMap.has(thread.parentId)) {
        const notifierChannelId = gameMediaMap.get(thread.parentId);
        const gameNotifierChannel = await client.channels.fetch(notifierChannelId);

        if (gameNotifierChannel.isTextBased()) {
            const messageUrl = `<https://discordapp.com/channels/${thread.guildId}/${thread.parentId}/${thread.id}>`;
            const postTitle = thread.name || "Unnamed Post"; // Assuming thread name is the post title.
            const author = thread.guild.members.cache.get(thread.ownerId) || await thread.guild.members.fetch(thread.ownerId).catch(() => null);
            const authorName = author ? (author.nickname || author.user.username) : "Unknown User";
            
            // Handling tags with backticks
            const tags = thread.appliedTags
                .map(s => thread.parent.availableTags.find(t => t.id === s))
                .map(x => ``${x.name}``) // Surrounding each tag with backticks
                .join(", ");
            const tagsMessage = tags ? `?️ Tags: ${tags}` : "Tags: None";

            const message = `? A new clip was posted in <#${thread.parentId}> by **${authorName}**. ?
[Go to clip - ${postTitle}](${messageUrl})
${tagsMessage}`;
            gameNotifierChannel.send(message);
        }
    }
});




相关问题
How can I make my bot works in multiple servers?

I know that this question has been asked for discord.py, but couldn t find a discord.js one Currently I m working on a small Discord Bot, and I would like to make it with possible that it can be used ...

Discord.js not recognizing file path as directory

I am trying to learn how to use the / command system in Discord.js, however, following the Discord.js guide results in the following error: Error: ENOTDIR: not a directory, scandir This is with the ...

Discord bot responds multiple times for one event

I want my bot to respond once to a command such as .on. However, it responds multiple times per input: The code is: client.on( message , message =>{ if(message.content === .on ){ ...

热门标签