Converting the vc command to a slash command
This commit is contained in:
parent
f89ff780f5
commit
4e773cf84d
@ -1,4 +1,5 @@
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
from discord import option
|
||||||
import core_utils
|
import core_utils
|
||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
@ -194,14 +195,15 @@ class ServerUtils(commands.Cog):
|
|||||||
await ctx.message.delete()
|
await ctx.message.delete()
|
||||||
await ctx.message.guild.leave()
|
await ctx.message.guild.leave()
|
||||||
|
|
||||||
@commands.command(name="vc")
|
@commands.slash_command(
|
||||||
|
name="vc",
|
||||||
|
description="Creates a role and voice channel of the same name",
|
||||||
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def vc(self, ctx: commands.Context, *, channel_role_name):
|
async def vc(self, ctx: commands.Context, channel_role_name):
|
||||||
# Check that the role/channel doesnt already exist
|
# Check that the role/channel doesnt already exist
|
||||||
# returns either a string or None, so we'll proceed on the None condition
|
# returns either a string or None, so we'll proceed on the None condition
|
||||||
if discord.utils.find(
|
if discord.utils.find(lambda r: r.name == channel_role_name, ctx.guild.roles):
|
||||||
lambda r: r.name == channel_role_name, ctx.message.guild.roles
|
|
||||||
):
|
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
":x: A role named `%s` already exists :x:" % channel_role_name
|
":x: A role named `%s` already exists :x:" % channel_role_name
|
||||||
)
|
)
|
||||||
@ -209,7 +211,7 @@ class ServerUtils(commands.Cog):
|
|||||||
|
|
||||||
# Create a role and assign it a random color
|
# Create a role and assign it a random color
|
||||||
try:
|
try:
|
||||||
role = await ctx.message.guild.create_role(
|
role = await ctx.guild.create_role(
|
||||||
name=channel_role_name,
|
name=channel_role_name,
|
||||||
mentionable=True,
|
mentionable=True,
|
||||||
hoist=True,
|
hoist=True,
|
||||||
@ -218,21 +220,19 @@ class ServerUtils(commands.Cog):
|
|||||||
|
|
||||||
overwrites = {
|
overwrites = {
|
||||||
role: discord.PermissionOverwrite(connect=True, speak=True),
|
role: discord.PermissionOverwrite(connect=True, speak=True),
|
||||||
ctx.message.guild.default_role: discord.PermissionOverwrite(
|
ctx.guild.default_role: discord.PermissionOverwrite(connect=False),
|
||||||
connect=False
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await ctx.message.guild.create_voice_channel(
|
await ctx.guild.create_voice_channel(
|
||||||
name=channel_role_name, bitrate=96000, overwrites=overwrites
|
name=channel_role_name, bitrate=96000, overwrites=overwrites
|
||||||
)
|
)
|
||||||
|
|
||||||
await ctx.reply(
|
await ctx.respond(
|
||||||
":white_check_mark: Created a role + voice channel for %s"
|
":white_check_mark: Created a role + voice channel for %s"
|
||||||
% role.mention
|
% role.mention
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.reply(":x: Error: %s :x:" % e)
|
await ctx.respond(":x: Error: %s :x:" % e)
|
||||||
|
|
||||||
@commands.command(name="help")
|
@commands.command(name="help")
|
||||||
async def help(self, ctx: commands.Context, method=None):
|
async def help(self, ctx: commands.Context, method=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user