say.py 849 B

12345678910111213141516171819202122232425262728
  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.")
  17. ):
  18. channel= discord.utils.get(ctx.guild.channels, id = int(channel_input[2:-1]))
  19. await channel.send(text)
  20. await ctx.respond("Message sent", ephemeral=True)
  21. def setup(bot: discord.Bot):
  22. bot.add_cog(Say(bot))