Made /join permission errors more obvious
parent
b8289aeab9
commit
986f3d46f8
|
@ -1,7 +1,7 @@
|
||||||
use log::trace;
|
use log::{error, trace};
|
||||||
use serenity::{
|
use serenity::{
|
||||||
builder::CreateApplicationCommand,
|
builder::CreateApplicationCommand,
|
||||||
model::prelude::interaction::application_command::ApplicationCommandInteraction,
|
model::prelude::{interaction::application_command::ApplicationCommandInteraction, Channel},
|
||||||
prelude::Context,
|
prelude::Context,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,15 +43,34 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||||
|
|
||||||
// Check for Voice Channel permissions
|
// Check for Voice Channel permissions
|
||||||
{
|
{
|
||||||
let channel = match ctx.cache.guild_channel(channel_id) {
|
let channel = match channel_id.to_channel(&ctx).await {
|
||||||
Some(channel) => channel,
|
Ok(channel) => match channel {
|
||||||
None => {
|
Channel::Guild(channel) => channel,
|
||||||
|
_ => {
|
||||||
respond_message(
|
respond_message(
|
||||||
&ctx,
|
&ctx,
|
||||||
&command,
|
&command,
|
||||||
EmbedBuilder::new()
|
EmbedBuilder::new()
|
||||||
.title("Cannot join voice channel")
|
.title("Cannot join voice channel")
|
||||||
.description("The voice channel you are in is not available")
|
.description("The voice channel you are in is not supported")
|
||||||
|
.status(Status::Error)
|
||||||
|
.build(),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(why) => {
|
||||||
|
error!("Failed to get channel: {}", why);
|
||||||
|
|
||||||
|
respond_message(
|
||||||
|
&ctx,
|
||||||
|
&command,
|
||||||
|
EmbedBuilder::new()
|
||||||
|
.title("Cannot join voice channel")
|
||||||
|
.description("The voice channel you are in is not available.\nI might not the permission to see this channel.")
|
||||||
.status(Status::Error)
|
.status(Status::Error)
|
||||||
.build(),
|
.build(),
|
||||||
true,
|
true,
|
||||||
|
@ -85,15 +104,34 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||||
|
|
||||||
// Check for Text Channel permissions
|
// Check for Text Channel permissions
|
||||||
{
|
{
|
||||||
let channel = match ctx.cache.guild_channel(&command.channel_id) {
|
let channel = match command.channel_id.to_channel(&ctx).await {
|
||||||
Some(channel) => channel,
|
Ok(channel) => match channel {
|
||||||
None => {
|
Channel::Guild(channel) => channel,
|
||||||
|
_ => {
|
||||||
respond_message(
|
respond_message(
|
||||||
&ctx,
|
&ctx,
|
||||||
&command,
|
&command,
|
||||||
EmbedBuilder::new()
|
EmbedBuilder::new()
|
||||||
.title("Cannot join voice channel")
|
.title("Cannot join voice channel")
|
||||||
.description("The text channel you are in is not available")
|
.description("The text channel you are in is not supported")
|
||||||
|
.status(Status::Error)
|
||||||
|
.build(),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(why) => {
|
||||||
|
error!("Failed to get channel: {}", why);
|
||||||
|
|
||||||
|
respond_message(
|
||||||
|
&ctx,
|
||||||
|
&command,
|
||||||
|
EmbedBuilder::new()
|
||||||
|
.title("Cannot join voice channel")
|
||||||
|
.description("The text channel you are in is not available.\nI might not have the permission to see this channel.")
|
||||||
.status(Status::Error)
|
.status(Status::Error)
|
||||||
.build(),
|
.build(),
|
||||||
true,
|
true,
|
||||||
|
@ -114,7 +152,9 @@ pub fn run(ctx: Context, command: ApplicationCommandInteraction) -> CommandOutpu
|
||||||
&command,
|
&command,
|
||||||
EmbedBuilder::new()
|
EmbedBuilder::new()
|
||||||
.title("Cannot join voice channel")
|
.title("Cannot join voice channel")
|
||||||
.description("I do not have the permissions to speak in this text channel")
|
.description(
|
||||||
|
"I do not have the permissions to send messages / links in this text channel",
|
||||||
|
)
|
||||||
.status(Status::Error)
|
.status(Status::Error)
|
||||||
.build(),
|
.build(),
|
||||||
true,
|
true,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use log::*;
|
use log::*;
|
||||||
use serenity::{
|
use serenity::{
|
||||||
async_trait,
|
async_trait,
|
||||||
model::prelude::{interaction::Interaction, Activity, Ready},
|
model::prelude::{interaction::Interaction, Activity, GuildId, Ready},
|
||||||
prelude::{Context, EventHandler},
|
prelude::{Context, EventHandler},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,6 +36,18 @@ impl EventHandler for Handler {
|
||||||
// INTERACTION_CREATE event, emitted when the bot receives an interaction (slash command, button, etc.)
|
// INTERACTION_CREATE event, emitted when the bot receives an interaction (slash command, button, etc.)
|
||||||
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
|
||||||
if let Interaction::ApplicationCommand(command) = interaction {
|
if let Interaction::ApplicationCommand(command) = interaction {
|
||||||
|
if let Ok(guild_id) = std::env::var("GUILD_ID") {
|
||||||
|
if let Ok(guild_id) = guild_id.parse::<u64>() {
|
||||||
|
let guild_id = GuildId(guild_id);
|
||||||
|
|
||||||
|
if let Some(interaction_guild_id) = command.guild_id {
|
||||||
|
if guild_id != interaction_guild_id {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Commands must only be executed inside of guilds
|
// Commands must only be executed inside of guilds
|
||||||
|
|
||||||
let guild_id = match command.guild_id {
|
let guild_id = match command.guild_id {
|
||||||
|
|
Loading…
Reference in New Issue