Skip to content

Instantly share code, notes, and snippets.

@SpencerSharkey
Created April 1, 2021 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpencerSharkey/7146f8549c09f20d83ce2fb455edb6dd to your computer and use it in GitHub Desktop.
Save SpencerSharkey/7146f8549c09f20d83ce2fb455edb6dd to your computer and use it in GitHub Desktop.
Pylon Public Stage Example
// Stage channels are here, and Pylon supports them!
// Here's an example that automatically invites users who "request to speak" to the stage.
// It also shows off the new iterVoiceStates function, and allows you
const logChannelId = '693184705805418578';
discord.on('VOICE_STATE_UPDATE', async (newState, oldState) => {
// Track voice state updates where a new member requests to speak.
if (
newState.channelId &&
newState.requestToSpeakTimestamp &&
!oldState.requestToSpeakTimestamp
) {
// Invite them to become a spekaer by unsupressing them.
await newState.edit({
suppress: false
});
const guild = await newState.getGuild();
let audienceCount = 0;
// new feature!
// find voice states in the specified channel and increase our audience count
for await (const state of guild.iterVoiceStates({
channelId: newState.channelId
})) {
// if they're suppressed, they are an audience member
if (state.suppress) {
audienceCount += 1;
}
}
// for fun, log a message to the given channel id.
const logChannel = await discord.getGuildTextChannel(logChannelId);
if (logChannel) {
await logChannel.sendMessage(
`You're on stage for **${audienceCount}** people, ${newState.member.toMention()}! Break a leg!`
);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment