say.py 933 B

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