some better transaction usage
This commit is contained in:
@@ -5,10 +5,10 @@ use poise::serenity_prelude as serenity;
|
||||
|
||||
/// Register an existing role as a user's custom role
|
||||
#[poise::command(slash_command, prefix_command, required_permissions = "MANAGE_ROLES")]
|
||||
pub async fn register(ctx: Context<'_>, user: serenity::User, role: serenity::Role) -> Result<(), Error> {
|
||||
let mut tx = ctx.data().database.begin().await?;
|
||||
|
||||
pub async fn register(ctx: Context<'_>, user: serenity::User, role: serenity::Role) -> Result<(), Error> {
|
||||
if let Some(guild) = ctx.guild_id() {
|
||||
let mut tx = ctx.data().database.begin().await?;
|
||||
|
||||
match super::get_user_role(user.id, guild, &mut *tx).await? {
|
||||
Some(role) => {
|
||||
let role = guild.role(ctx, role).await?;
|
||||
@@ -20,6 +20,8 @@ pub async fn register(ctx: Context<'_>, user: serenity::User, role: serenity::Ro
|
||||
.bind(guild.get() as i64)
|
||||
.bind(role.id.get() as i64)
|
||||
.execute(&mut *tx).await?;
|
||||
|
||||
tx.commit().await?;
|
||||
|
||||
let member = guild.member(ctx, user.id).await?;
|
||||
member.add_role(ctx, role.id).await?;
|
||||
@@ -31,6 +33,5 @@ pub async fn register(ctx: Context<'_>, user: serenity::User, role: serenity::Ro
|
||||
ctx.reply("This command can only be run in a guild!").await?;
|
||||
}
|
||||
|
||||
tx.commit().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user