Ask coding questions

← Back to all posts
CHAT room adding commands
PixelNinja (310)

Hi, what would I have to do to this code to add commands and be able to kick people/ delete messages? This would need to be only if there name was something special like a password. At the moment, I have added my own name by using 54r3 as the name. Any ideas?

Answered by Geocube101 (623) [earned 5 cycles]
View Answer
Geocube101 (623)

The owner could send an event to the server, which will broadcast an event to all clients with data such as the target username. Any client with the matching username will send an event to the server (to get the clients socket). The server can then call the socket.disconnect() to kick the clients socket.

I normally create a kick page and redirect the client there, otherwise, they will remain in the room, but won't be able to do anything

PixelNinja (310)

@Geocube101 Ok, Thanks. Will have a look

PixelNinja (310)

@Geocube101 I am not sure how to target it at a user i have now set it up so if you type leave, then you get disconnected, but still cant aim it at a specific user

Geocube101 (623)

@RossJames Sorry for long response time. The way I did it, was getting a string input (the client to kick's username), and emitting it to the server. The server then would emit to all clients the username. If any client had that username, it would emit back to the server. Upon receiving the event, the socket which sent the event is kicked.

You could either setup an input field or a prompt to get the target client's username.
You could also have a button which receives the username (from one of the methods listed above) and fires a function

//The owner
//The following function can be linked to a button
function kick_user(username)
  socket.emit('kick_user', username)
//Server Side - Inside the 'connection' event handler
socket.on('kick_user', function(username)
  io.sockets.emit('kick', username);
socket.on('kick_confirmed', function()
//Client Side
//'currentUsername' is the name that the client has selected for themselves
socket.on('kick', function(username)
  if (username == currentUsername)
WagWanMa (0)

hello so look I have done my thing when I say !report and it says the thingy but I can't say
if message.content.startswith('!report'):
await'Please if You Want to report someone or something dm @Owner / @Co-Owner') what do I say like if someone say !hello and the bot responds with hey

PixelNinja (310)

@WagWanMa I'm sure is discord.js. Are you sure you aren't getting confused?

Wubium_Dubium (0)

This is not your own It is stolen from @Jser, and it can get you a strike on here, or maybe a kick or ban. I do not know how it works, but I believe there will be consequences if this is plagarism.

themaka (187)

Hi there @Wubium_Dubium and others.

Let's ease up on accusing people of theft.

It's not 'stolen' -- repls are public and may be forked by anyone. Presenting it as your own work is certainly unethical, but it is very common to fork a repl (or clone a GitHub repo, etc) as a starting place to work from and nothing is wrong with that.

@RossJames asked about adding more commands to the chat - I don't see any claims he was the original author, so I'm not sure why we're accusing him of theft.

That said, it would be nice if you credited the original creator in a comment, @RossJames

JSer (84)

Oh crap, who forked my repl?

PYer (3656)

This seems pretty similar to something i saw from @JSer