say.py 952 B

12345678910111213141516171819202122232425262728293031
  1. import discord
  2. from discord.ext import commands
  3. from discord.commands import Option
  4. from discord.commands import slash_command
  5. import os
  6. from dotenv import load_dotenv
  7. class say(commands.Cog):
  8. def __init__(self, bot: discord.Bot):
  9. self.bot = bot
  10. #Command initialization
  11. @slash_command(description="Let the bot send a message")
  12. async def say(
  13. self,
  14. ctx,
  15. text: str = Option(description="Input the text you want to send"),
  16. channel_input: discord.TextChannel = Option(description="Select the channel,where you want to send the message.", required=False)
  17. ):
  18. if channel_input is None:
  19. channel = ctx.channel
  20. else:
  21. channel = discord.utils.get(ctx.guild.channels, id = int(channel_input[2:-1]))
  22. await channel.send(text)
  23. await ctx.respond("Message sent", ephemeral=True)
  24. def setup(bot: discord.Bot):
  25. bot.add_cog(say(bot))