[RS] JesseUCAVedYou [EN]
[RS] JesseUCAVedYou [EN]
Explore posts from servers
DIAdiscord.js - Imagine an app
Created by [RS] JesseUCAVedYou [EN] on 10/8/2024 in #djs-questions
Keeping A Channel Polls Only
I'm trying to make a specific channel polls only. Since Discord doesn't have a permission set for this I've setup my bot to detect the difference in a poll message and a regular message. Regular messages get deleted from the channel and the user a DM stating why. Polls get ignored. This has been successful. What isn't successful though is when the poll ends and Discord sends out the notification message stating the poll has ended it gets deleted as well. Is there a way to detect poll end messages too? I tried having the bot see if the messages contained specific text, but no luck.
// The channel ID you want to monitor
const pollChannelId = '1292516925494267954';

// Check if the message is a poll ending message (adjust based on your poll ending format)
function isPollEndMessage(message) {
return message.content.includes("has closed"); // Customize this if necessary
}

client.on('messageCreate', async (message) => {
// Ignore messages from bots
if (message.author.bot) return;

// Only check messages from the specified channel
if (message.channel.id === pollChannelId) {
// If it's a poll, process as normal
if (message.poll) {
// Check if the poll has more than 5 options
if (message.poll.answers && message.poll.answers.size > 4) {
try {
// Delete the poll
await message.delete();
// Notify the user via DM
await message.author.send(`Your poll was deleted because it exceeded the limit of 4 answers.`);
} catch (error) {
console.error(`Error deleting poll or sending DM: ${error}`);
}
}
return; // End execution if the message is a valid poll
}

// If the message is the poll ending message, don't delete it
if (isPollEndMessage(message)) {
return; // Do nothing if it's the poll end message
}

// If it's not a poll or an ending message, delete the message
try {
await message.delete();
await message.author.send(`Your message was deleted because ${message.channel} is for polls only.`);
} catch (error) {
console.error(`Error deleting message or sending DM: ${error}`);
}
}
});
// The channel ID you want to monitor
const pollChannelId = '1292516925494267954';

// Check if the message is a poll ending message (adjust based on your poll ending format)
function isPollEndMessage(message) {
return message.content.includes("has closed"); // Customize this if necessary
}

client.on('messageCreate', async (message) => {
// Ignore messages from bots
if (message.author.bot) return;

// Only check messages from the specified channel
if (message.channel.id === pollChannelId) {
// If it's a poll, process as normal
if (message.poll) {
// Check if the poll has more than 5 options
if (message.poll.answers && message.poll.answers.size > 4) {
try {
// Delete the poll
await message.delete();
// Notify the user via DM
await message.author.send(`Your poll was deleted because it exceeded the limit of 4 answers.`);
} catch (error) {
console.error(`Error deleting poll or sending DM: ${error}`);
}
}
return; // End execution if the message is a valid poll
}

// If the message is the poll ending message, don't delete it
if (isPollEndMessage(message)) {
return; // Do nothing if it's the poll end message
}

// If it's not a poll or an ending message, delete the message
try {
await message.delete();
await message.author.send(`Your message was deleted because ${message.channel} is for polls only.`);
} catch (error) {
console.error(`Error deleting message or sending DM: ${error}`);
}
}
});
14 replies
DIAdiscord.js - Imagine an app
Created by [RS] JesseUCAVedYou [EN] on 10/6/2024 in #djs-questions
Bot Not Updating Voice Permissions
I'm trying to have an event voice channel that is locked(everyone cannot connect or speak), but when an event is live have the perms update so everyone can connect and speak to that channel. There are no console errors I am seeing, and I know it's detecting an active event since the channels status gets updated to reflect the event name as it's supposed to. Can someone give this a look over and see what I'm doing wrong in the permissions area?
const { Events, PermissionFlagsBits } = require('discord.js');
const voiceChannelId = '1284713593056661618'; // Your target voice channel ID

client.on(Events.GuildScheduledEventUpdate, async (oldEvent, newEvent) => {
const guild = newEvent.guild;
const voiceChannel = guild.channels.cache.get(voiceChannelId);

if (!voiceChannel) {
console.error(`Voice channel with ID ${voiceChannelId} not found.`);
return;
}

// Ensure we only react to the relevant event with the specified channel
if (newEvent.channelId !== voiceChannelId) return;

// Handle 10 minutes before event start
const now = new Date();
const tenMinutesBeforeStart = new Date(newEvent.scheduledStartTimestamp - 10 * 60 * 1000);

if (now >= tenMinutesBeforeStart && newEvent.status === 'SCHEDULED') {
// Unlock the channel 10 minutes before the event starts
await updateChannelPermissions(voiceChannel, true);
await voiceChannel.setName('Event Starting Soon - Channel Unlocked');
}

// Handle when event becomes active
if (newEvent.status === 'ACTIVE') {
// Set channel name to event name and keep it unlocked
await voiceChannel.setName(newEvent.name);
await updateChannelPermissions(voiceChannel, true);
}

// Handle when the event is canceled or completed
if (newEvent.status === 'COMPLETED' || newEvent.status === 'CANCELED') {
const events = await guild.scheduledEvents.fetch();
const activeEvents = events.filter(event => event.channelId === voiceChannelId && event.status === 'ACTIVE');

if (activeEvents.size === 0) {
// Lock the channel 10 minutes after the event ends if no other active events
setTimeout(async () => {
const currentEvents = await guild.scheduledEvents.fetch();
const currentActiveEvents = currentEvents.filter(event => event.channelId === voiceChannelId && event.status === 'ACTIVE');
if (currentActiveEvents.size === 0) {
await voiceChannel.setName('Event Ended - Channel Locking Soon');
await updateChannelPermissions(voiceChannel, false);
}
}, 10 * 60 * 1000); // 10 minutes
}
}
});

// Periodically check for upcoming events and handle permissions
setInterval(async () => {
const guilds = client.guilds.cache;
for (const guild of guilds.values()) {
const events = await guild.scheduledEvents.fetch();
const upcomingEvents = events.filter(event => event.channelId === voiceChannelId && event.scheduledStartTimestamp - Date.now() < 10 * 60 * 1000 && event.status === 'SCHEDULED');

// Handle unlocking channels for any events starting in less than 10 minutes
for (const event of upcomingEvents.values()) {
const voiceChannel = guild.channels.cache.get(event.channelId);
if (voiceChannel) {
await updateChannelPermissions(voiceChannel, true);
await voiceChannel.setName('Event Starting Soon - Channel Unlocked');
}
}
}
}, 5 * 60 * 1000); // Check every 5 minutes

// Helper function to update permissions
async function updateChannelPermissions(channel, allowAccess) {
const permissions = {
Connect: allowAccess,
Speak: allowAccess,
};
await channel.permissionOverwrites.edit(channel.guild.roles.everyone, permissions);
}
const { Events, PermissionFlagsBits } = require('discord.js');
const voiceChannelId = '1284713593056661618'; // Your target voice channel ID

client.on(Events.GuildScheduledEventUpdate, async (oldEvent, newEvent) => {
const guild = newEvent.guild;
const voiceChannel = guild.channels.cache.get(voiceChannelId);

if (!voiceChannel) {
console.error(`Voice channel with ID ${voiceChannelId} not found.`);
return;
}

// Ensure we only react to the relevant event with the specified channel
if (newEvent.channelId !== voiceChannelId) return;

// Handle 10 minutes before event start
const now = new Date();
const tenMinutesBeforeStart = new Date(newEvent.scheduledStartTimestamp - 10 * 60 * 1000);

if (now >= tenMinutesBeforeStart && newEvent.status === 'SCHEDULED') {
// Unlock the channel 10 minutes before the event starts
await updateChannelPermissions(voiceChannel, true);
await voiceChannel.setName('Event Starting Soon - Channel Unlocked');
}

// Handle when event becomes active
if (newEvent.status === 'ACTIVE') {
// Set channel name to event name and keep it unlocked
await voiceChannel.setName(newEvent.name);
await updateChannelPermissions(voiceChannel, true);
}

// Handle when the event is canceled or completed
if (newEvent.status === 'COMPLETED' || newEvent.status === 'CANCELED') {
const events = await guild.scheduledEvents.fetch();
const activeEvents = events.filter(event => event.channelId === voiceChannelId && event.status === 'ACTIVE');

if (activeEvents.size === 0) {
// Lock the channel 10 minutes after the event ends if no other active events
setTimeout(async () => {
const currentEvents = await guild.scheduledEvents.fetch();
const currentActiveEvents = currentEvents.filter(event => event.channelId === voiceChannelId && event.status === 'ACTIVE');
if (currentActiveEvents.size === 0) {
await voiceChannel.setName('Event Ended - Channel Locking Soon');
await updateChannelPermissions(voiceChannel, false);
}
}, 10 * 60 * 1000); // 10 minutes
}
}
});

// Periodically check for upcoming events and handle permissions
setInterval(async () => {
const guilds = client.guilds.cache;
for (const guild of guilds.values()) {
const events = await guild.scheduledEvents.fetch();
const upcomingEvents = events.filter(event => event.channelId === voiceChannelId && event.scheduledStartTimestamp - Date.now() < 10 * 60 * 1000 && event.status === 'SCHEDULED');

// Handle unlocking channels for any events starting in less than 10 minutes
for (const event of upcomingEvents.values()) {
const voiceChannel = guild.channels.cache.get(event.channelId);
if (voiceChannel) {
await updateChannelPermissions(voiceChannel, true);
await voiceChannel.setName('Event Starting Soon - Channel Unlocked');
}
}
}
}, 5 * 60 * 1000); // Check every 5 minutes

// Helper function to update permissions
async function updateChannelPermissions(channel, allowAccess) {
const permissions = {
Connect: allowAccess,
Speak: allowAccess,
};
await channel.permissionOverwrites.edit(channel.guild.roles.everyone, permissions);
}
3 replies
BBattleMetrics
Created by [RS] JesseUCAVedYou [EN] on 8/10/2024 in #support-forum
7 Days to Die - Player Leaves
It seems that with this last 7 Days to Die update triggers no longer fire when users leave the server. Guessing a variable or something got changed on their end. 🙂 Just figured I'd let you know.
2 replies
BBattleMetrics
Created by [RS] JesseUCAVedYou [EN] on 8/7/2024 in #support-forum
7 Days to Die - Joining Trigger - Triggers Twice
No description
10 replies
BBattleMetrics
Created by [RS] JesseUCAVedYou [EN] on 7/25/2024 in #support-forum
7 Days to Die Chats
Chat messages from 7 Days to Die don't seem to work anymore. On the website console you can't see what players say anymore and when using this code in a webhook no chats get sent to Discord.
{
"content": "[{{timestamp}}]\n**[{{msg.channel}} Chat] {{player.name}}:** {{msg.body}}"
}
{
"content": "[{{timestamp}}]\n**[{{msg.channel}} Chat] {{player.name}}:** {{msg.body}}"
}
This same exact code I use for sending Battlebit Remastered chats to a webhook. Both games support the same variables so I don't believe it's the code.
7 replies
BBattleMetrics
Created by [RS] JesseUCAVedYou [EN] on 5/16/2024 in #support-forum
Few variables not working - Battlebit
Tried to create a message for a command in game. Variables weren't working so I added all the squad ones to a console log and got this as the result: (Activity Log) JesseUCAVedYou used the !lead command and became squad leader of {{player.squadName}}. User ID {{user.id}} User Nickname {{user.nickname}} Team Index {{player.teamIndex}} BattleBit Remastered Squad Index {{player.squadIndex}} BattleBit Remastered Squad Name {{player.squadName}} BattleBit Remastered Is Squad Leader true (5) (Trigger).
12 replies