-2

I have tried different options, and this one was the one that I desired the most, but I cannot seem to get it working. Could I get some help? (Sorry I am very new to coding)

This is my code:

import discord
from discord.ext import commands

client = discord.Client()
bot = commands.Bot(command_prefix='-')

@bot.command()
async def speak(ctx, *, text):
  if ctx.message.author.id == ID here:
    message = ctx.message
    await message.delete()
    
    await ctx.send(f"{text}")
  else:
    await ctx.send('I need text!')

Thanks

  • Can you please elaborate on "Cannot get it working"? E.g. error messages, wrong text etc. – Kelo May 16 '21 at 15:00
  • Can you describe the way how it should behave? I copied it and no errors occured... – loloToster May 16 '21 at 15:13
  • Yes so in the terminal I do not get any error notifications, but when I try to use it in discord, it does not work. I use "-say (message)" but it does not cooperate. Am I supposed to execute it differently? – Demented_Elmo May 16 '21 at 16:56
  • Did you replace the `ID here` part with an actual ID? Did you start the bot? – 12944qwerty May 16 '21 at 18:40
  • Yes I did both. I have run the bot before and have a few async def on_message commands, it is just this one that I am having trouble with – Demented_Elmo May 16 '21 at 18:45

1 Answers1

0

Your else statement makes little sense here. It is best to set up the condition differently, that you want text once and if that does not happen, then there is an else argument.

I don't know if this is relevant either, but apparently it looks like you want only one person to be able to execute this command. For the owner there would be:

@commands.is_owner()

But if you want to make it refer to another person use:

@bot.command()
@commands.is_owner() # If you want to set this condition
async def say(ctx, *, text: str = None):
    if ctx.message.author is not ID_You_Want:
        await ctx.send("You are not allowed to use the command.")
        return # Do not proceed
    if text is None: # If just say is passed with no text
        await ctx.send("Please insert a text.")
    else:
        await ctx.send(text) # Send the text

Optional: You can also delete the command that was send with ctx.message.delete()

Your command is not executing because you defined client and bot. Simply remove client = discord.Client() and you will be fine.

Dominik
  • 3,612
  • 2
  • 11
  • 44