Welcome to the Power Users community on Codidact!
Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.
How can I disable channel drag and drop in Discord?
When using Discord in a web browser, on a server where I have admin privileges, I sometimes find that I've accidentally moved a channel, which affects everyone on the server and can affect channel permissions, so that's bad. You move channels by clicking and dragging, but apparently the interface is more sensitive than I'm used to: I think when this happens I move the mouse to a channel and click on it to view it, but maybe the mouse was still slightly in motion when I clicked? I'm not sure, but training myself isn't working and I don't have this problem with other UIs. I'm looking for a way to add some friction so I can't accidentally do this, without giving up my admin rights in general. (I do need those.)
I searched for a way to lock the channels or otherwise prevent this and found lots of other people with my problem (1 2 3), but no solutions. A client-side solution (for example a userscript) would be fine (but I don't know enough to write it). I'm not interested in switching to an app; I want to use Discord in my browser.
How can I stop accidentally messing with the channels list?
1 answer
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
Monica Cellio |
Thread: Works for me This is great, thank you! I've just installed this using TamperMonkey and it works as advertised. |
Dec 3, 2023 at 22:15 |
Since there seem to be no userscripts for this, I wrote one myself. It should work with all major userscript managers and browsers.
The script prevents the dragstart
event and thus drag and drop for the channel list. Additionally, there is a button to reactivate drag and drop if you want to rearrange the channels or drag users to different voice channels without reloading the page.
// ==UserScript==
// @name Discord channel drag and drop disabler
// @version 1.0
// @description Disables channel drag and drop in Discord web app
// @author Zer0
// @match https://discord.com/**
// @grant none
// ==/UserScript==
(async () => {
'use strict';
function modifyChannelList(channelListElement) {
let dragEnabled = false;
// Add container element
const container = document.createElement('div');
container.style.paddingLeft = '8px';
container.style.paddingBottom = '8px';
channelListElement.appendChild(container);
// Add toggle button with discord-like styling
const toggleButton = document.createElement('button');
toggleButton.style.color = '#FFF';
toggleButton.style.backgroundColor = 'rgb(71, 82, 196)';
toggleButton.style.borderRadius = '3px';
toggleButton.style.padding = '2px 16px';
toggleButton.style.width = '100%';
function updateButton(enabled) {
toggleButton.innerHTML = enabled ? 'Disabled Drag and Drop' : 'Enable Drag and Drop';
}
updateButton(dragEnabled);
toggleButton.addEventListener('click', () => {
dragEnabled = !dragEnabled;
updateButton(dragEnabled);
});
container.appendChild(toggleButton);
function addDragHandler(elements) {
elements.forEach(e => {
e.addEventListener('dragstart', ev => {
if (!dragEnabled) {
// Prevent channel drag and drop
ev.stopImmediatePropagation();
// Prevent link drag and drop (browser default)
ev.preventDefault();
}
});
});
}
// Add custom drag handler to all channel elements
addDragHandler(channelListElement.querySelectorAll('li'));
// Add custom drag handler to all future channel elements (when a new channel is created)
const observer = new MutationObserver(m => addDragHandler(m.flatMap(e => [...e.addedNodes]).filter(e => e instanceof HTMLElement && e.tagName === 'LI')));
observer.observe(channelListElement, { childList: true, subtree: true });
return () => observer.disconnect();
}
let channels = document.getElementById('channels');
let cleanup = null;
if (channels) {
cleanup = modifyChannelList(channels);
}
// Searches for the channel list element if the site changes
const mainObserver = new MutationObserver(() => {
const newChannels = document.getElementById('channels');
if (newChannels !== null && channels !== newChannels) {
channels = newChannels;
if (cleanup) {
cleanup();
}
cleanup = modifyChannelList(channels);
}
});
mainObserver.observe(document.body, { childList: true, subtree: true });
})();
0 comment threads