0

I tried to make a command that will send the message to the specified channel and get the below error

Command raised an exception: AttributeError: 'NoneType' object has no attribute 'send'

@client.command(name="chmsg")
async def _chmsg(ctx):

    def check(msg):
        return msg.author == ctx.author and \
               msg.channel == ctx.channel

    await ctx.send("Message")
    mestoc = await client.wait_for("message", check=check)
    await ctx.send("Channel id")
    chasend = await client.wait_for("message", check=check)
    mestoch = str(mestoc.content)
    cha = str(chasend.content)
    channel = client.get_channel(cha)
    await channel.send(f"{mestoch}")
1
  • This looks way too complicated for what could be such a simple command. Are you just looking for a command that sends something to a certain channel? Commented Apr 14, 2021 at 17:19

1 Answer 1

1
  1. You don't have to convert mestoc.content as a string as it is already a string

  2. You need cha as an integer, not as a string so you can get the channel

So your revised code looks like

@client.command(name="chmsg")
async def _chmsg(ctx):

    def check(msg):
        return msg.author == ctx.author and \
               msg.channel == ctx.channel

    await ctx.send("Message")
    mestoc = await client.wait_for("message", check=check)
    await ctx.send("Channel ID")
    chasend = await client.wait_for("message", check=check)
    mestoch = mestoc.content
    cha = int(chasend.content)
    channel = client.get_channel(cha)
    await channel.send(f"{mestoch}")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.