import type { Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; export class PrefixCommand extends Command { description = "Views or changes the bot's prefix." ; args = "[prefix:string]" ; allowdisable = false ; async run ( msg , _pargs , args ) { const prefix = args . join ( " " ) . trim ( ) ; let guildconfig = await this . bot . db . getGuildConfig ( msg . channel . guild . id ) ; if ( ! args . length && ! guildconfig ?. prefix ) { return msg . createEmbed ( `🤖 ${ msg . string ( "global.PREFIX" ) }` , `${ msg . string ( "global.SERVER_PREFIX" , { prefix : this . bot . config . prefixes [ 0 ] } ) }` ) ; } if ( ! args . length ) { return msg . createEmbed ( `🤖 ${ msg . string ( "global.PREFIX" ) }` , `${ msg . string ( "global.SERVER_PREFIX" , { prefix : guildconfig . prefix } ) }` ) ; } if ( prefix . length > 15 ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "general.PREFIX_TOOLONG" ) , "error" ) ; if ( ! msg . member ?. permissions ?. has ( "manageGuild" ) || ( guildconfig ?. staffRole && ! msg . member ?. roles ?. includes ( guildconfig . staffRole ) ) ) { return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "general.PREFIX_NOPERMISSIONS" ) , "error" ) ; } if ( ! guildconfig ) { await this . bot . db . insertBlankGuildConfig ( msg . channel . guild . id ) ; guildconfig = { id : msg . channel . guild . id , prefix : prefix } ; } guildconfig . prefix = prefix ; await this . bot . db . updateGuildConfig ( msg . channel . guild . id , guildconfig ) ; this . bot . emit ( "prefixUpdate" , msg . channel . guild , msg . member , prefix ) ; msg . createEmbed ( msg . string ( "global.SUCCESS" ) , msg . string ( "general.PREFIX_SET" , { prefix : prefix } ) , "success" ) ; } }