Single Click To Copy Discord Message ID

Click any Discord message to copy its message ID

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Single Click To Copy Discord Message ID
// @namespace    https://greasyfork.org/users/1179204
// @version      0.0.1
// @description  Click any Discord message to copy its message ID
// @author       KaKa
// @match        https://discord.com/channels/*
// @license      MIT
// ==/UserScript==
(function () {
    'use strict';

    document.addEventListener('click', function (event) {
        const messageElement = event.target.closest('[id^="chat-messages-"]');
        if (!messageElement) return;

        const rawId = messageElement.id;
        if (!rawId.startsWith('chat-messages-')) return;

        const fullId = rawId.substring('chat-messages-'.length);
        const parts = fullId.split('-');
        const messageId = parts[1] || parts[0];

        navigator.clipboard.writeText(messageId).then(() => {
            messageElement.style.outline = '2px solid red';
            setTimeout(() =>{
                messageElement.style.outline = ''}, 500);
        }).catch(err => {
            console.error('Failed to copy message ID:', err);
        });
    });
})();