#I wanted to create a discord.js code for my bot that using External app Command user spam

21 messages · Page 1 of 1 (latest)

rain whale
#

I want to delete the message & give timeout the executed user and this bot is not inside the server but it spamming

hasty citrusBOT
wispy python
#

or at least something in that interaction metadata should

#

also you could just remove permissions for using external apps too

#

-# (if you didnt already know they are abusing user installable bot)

rain whale
rain whale
sand marsh
misty oracle
modern sageBOT
misty oracle
#

Get the member from the guild by their user id and time them out. Or use <Guild>.members.edit(...) with communicationDisabledUntil to directly time them out without having to fetch or cache them

rain whale
#

client.on('messageCreate', async (message) => {
if (message.type !== MessageType.ChatInputCommand) return;

try {
const isBotInServer = await message.guild.members.fetch(message.author.id).catch(() => null);

if (isBotInServer) return;

const executorId = message.interactionMetadata?.user?.id;

if (executorId) {
  const memberToPunish = await message.guild.members.fetch(executorId).catch(() => null);

  if (memberToPunish) {
    await memberToPunish.timeout(60 * 60 * 1000, 'Using unauthorized external apps/spamming');
    console.log(⁨`Timed out ${memberToPunish.user.tag} for external app spam.`⁩);
  }
}

if (message.deletable) {
  await message.delete();
  console.log(⁨`Deleted spam message from external bot: ${message.author.tag}`⁩);
}

} catch (error) {
console.error('Error handling external app:', error);
}
});

#

I have created this but not working idk why

misty oracle
#

Those aren't chatinputcommands, so your message type doesn't match

wispy python
#

but yeah i was getting ahead of myself, qjuh's right that it exits too early

rain whale
#

client.on('messageCreate', async (message) => {
const metadata = message.interactionMetadata;
if (!metadata) return;

const isUserInstalled = !metadata.authorizingIntegrationOwners.has('0');

if (isUserInstalled) {
try {
const executorId = metadata.user?.id;

  if (executorId) {
    const member = await message.guild.members.fetch(executorId).catch(() => null);
    
    if (member) {
      await member.timeout(60 * 60 * 1000, 'Using unauthorized user-installed apps');
      console.log(⁨`Timed out ${member.user.tag} for external app usage.`⁩);
    }
  }

  if (message.deletable) await message.delete();

} catch (error) {
  console.error('Error handling external app:', error.message);
}

}
});

Like I have did this but not working

rain whale
#

hello?

misty oracle