some better transaction usage

This commit is contained in:
2024-12-10 15:41:49 -05:00
parent 0b0888e9a8
commit f09280260e
5 changed files with 15 additions and 13 deletions

View File

@@ -6,9 +6,9 @@ use poise::serenity_prelude::EditRole;
/// Change the name of your personal role
#[poise::command(slash_command, prefix_command)]
pub async fn name(ctx: Context<'_>, name: String) -> Result<(), Error> {
let mut tx = ctx.data().database.begin().await?;
if let Some(guild) = ctx.guild_id() {
let mut tx = ctx.data().database.begin().await?;
let role = match super::get_user_role(ctx.author().id, guild, &mut *tx).await? {
Some(role) => role,
None => {
@@ -20,11 +20,11 @@ pub async fn name(ctx: Context<'_>, name: String) -> Result<(), Error> {
.bind(guild.get() as i64)
.execute(&mut *tx).await?;
tx.commit().await?;
let member = guild.member(ctx, ctx.author().id).await?;
member.add_role(ctx, role.clone()).await?;
tx.commit().await?;
ctx.reply(format!("You've been given the {} role!", role)).await?;
return Ok(());