say.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. intents = discord.Intents.default()
  11. intents.message_content = True
  12. intents.members = True
  13. intents.guilds = True
  14. intents.reactions = True
  15. client = discord.Client(intents=intents)
  16. debug_guilds_up = []
  17. server_token = os.getenv("SERVER").split(",")
  18. for i in range(len(server_token)):
  19. debug_guilds_up.append(int(server_token[i]))
  20. bot = commands.Bot(
  21. command_prefix=commands.when_mentioned_or("!"),
  22. description="VicePD Bot",
  23. intents=intents,
  24. debug_guilds=debug_guilds_up if debug_guilds_up else None
  25. )
  26. #Command initialization
  27. @slash_command(description="Let the bot send a message")
  28. async def say(
  29. self,
  30. ctx,
  31. text: str = Option(description="Input the text you want to send"),
  32. channel_input: discord.TextChannel = Option(description="Select the channel,where you want to send the message.")
  33. ):
  34. channel= discord.utils.get(ctx.guild.channels, id = int(channel_input[2:-1]))
  35. await channel.send(text)
  36. await ctx.respond("Message sent", ephemeral=True)
  37. def setup(bot: discord.Bot):
  38. bot.add_cog(Say(bot))