Print a variable output in a 400 empty message code using PythonHow to flush output of print function?How to print to stderr in Python?I cannot make bot join discord voice channels using the python discord modulediscord and bot making: i cant seem to get my bot to post a web parsed materialImporting tensorflow not working when upgradedDiscord.py Bot Not Leaving Voice ChannelI use asynchronous and requests and urllib are blockingFailed to establish a new connection Discord.pyError give role when a user add reaction Discord.pydiscord bot autorole — in _run_event yield from getattr(self, event)(*args, **kwargs)

Different meanings of こわい

What does the same-ish mean?

Blending or harmonizing

Why are UK visa biometrics appointments suspended at USCIS Application Support Centers?

How to coordinate airplane tickets?

Does int main() need a declaration on C++?

What's the meaning of "Sollensaussagen"?

What is an equivalently powerful replacement spell for the Yuan-Ti's Suggestion spell?

In Bayesian inference, why are some terms dropped from the posterior predictive?

Why do I get negative height?

How dangerous is XSS

Why is the sentence "Das ist eine Nase" correct?

What is required to make GPS signals available indoors?

Do creatures with a listed speed of "0 ft., fly 30 ft. (hover)" ever touch the ground?

Forgetting the musical notes while performing in concert

How can a day be of 24 hours?

Convert seconds to minutes

How to remove border from elements in the last row?

how do we prove that a sum of two periods is still a period?

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

How to stretch the corners of this image so that it looks like a perfect rectangle?

Is there a hemisphere-neutral way of specifying a season?

files created then deleted at every second in tmp directory

Getting extremely large arrows with tikzcd



Print a variable output in a 400 empty message code using Python


How to flush output of print function?How to print to stderr in Python?I cannot make bot join discord voice channels using the python discord modulediscord and bot making: i cant seem to get my bot to post a web parsed materialImporting tensorflow not working when upgradedDiscord.py Bot Not Leaving Voice ChannelI use asynchronous and requests and urllib are blockingFailed to establish a new connection Discord.pyError give role when a user add reaction Discord.pydiscord bot autorole — in _run_event yield from getattr(self, event)(*args, **kwargs)













1















Problem:



I am trying to code a bot for Discord so that to take a variable and send that as a message. For example, "a" is set to 42 and I want the bot to print in chat "The number is 42 author name":



a = 32

if message.content.startswith('!gap'):
msg = print('a'.format(message))
await client.send_message(message.channel, msg)


Error:



Ignoring exception in on_message
Traceback (most recent call last):
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordclient.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:UserstrevoDesktopdcbotreply.py", line 16, in on_message
await client.send_message(message.channel, msg)
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordclient.py", line 1152, in send_message
data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordhttp.py", line 200, in request
raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message


I appreciate explanations!










share|improve this question
























  • Are you aware that 'a'.format(message) will just return 'a'?

    – Mike Holt
    Mar 8 at 20:37












  • Yes, I realized that but right now I am just trying to use print as a message.

    – TrevTV
    Mar 8 at 20:38















1















Problem:



I am trying to code a bot for Discord so that to take a variable and send that as a message. For example, "a" is set to 42 and I want the bot to print in chat "The number is 42 author name":



a = 32

if message.content.startswith('!gap'):
msg = print('a'.format(message))
await client.send_message(message.channel, msg)


Error:



Ignoring exception in on_message
Traceback (most recent call last):
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordclient.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:UserstrevoDesktopdcbotreply.py", line 16, in on_message
await client.send_message(message.channel, msg)
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordclient.py", line 1152, in send_message
data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordhttp.py", line 200, in request
raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message


I appreciate explanations!










share|improve this question
























  • Are you aware that 'a'.format(message) will just return 'a'?

    – Mike Holt
    Mar 8 at 20:37












  • Yes, I realized that but right now I am just trying to use print as a message.

    – TrevTV
    Mar 8 at 20:38













1












1








1








Problem:



I am trying to code a bot for Discord so that to take a variable and send that as a message. For example, "a" is set to 42 and I want the bot to print in chat "The number is 42 author name":



a = 32

if message.content.startswith('!gap'):
msg = print('a'.format(message))
await client.send_message(message.channel, msg)


Error:



Ignoring exception in on_message
Traceback (most recent call last):
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordclient.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:UserstrevoDesktopdcbotreply.py", line 16, in on_message
await client.send_message(message.channel, msg)
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordclient.py", line 1152, in send_message
data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordhttp.py", line 200, in request
raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message


I appreciate explanations!










share|improve this question
















Problem:



I am trying to code a bot for Discord so that to take a variable and send that as a message. For example, "a" is set to 42 and I want the bot to print in chat "The number is 42 author name":



a = 32

if message.content.startswith('!gap'):
msg = print('a'.format(message))
await client.send_message(message.channel, msg)


Error:



Ignoring exception in on_message
Traceback (most recent call last):
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordclient.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "C:UserstrevoDesktopdcbotreply.py", line 16, in on_message
await client.send_message(message.channel, msg)
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordclient.py", line 1152, in send_message
data = yield from self.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed)
File "C:UserstrevoAppDataLocalProgramsPythonPython36-32libsite-packagesdiscordhttp.py", line 200, in request
raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400): Cannot send an empty message


I appreciate explanations!







python discord discord.py bad-request






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 21:30









Emma

1,1231920




1,1231920










asked Mar 8 at 20:31









TrevTVTrevTV

85




85












  • Are you aware that 'a'.format(message) will just return 'a'?

    – Mike Holt
    Mar 8 at 20:37












  • Yes, I realized that but right now I am just trying to use print as a message.

    – TrevTV
    Mar 8 at 20:38

















  • Are you aware that 'a'.format(message) will just return 'a'?

    – Mike Holt
    Mar 8 at 20:37












  • Yes, I realized that but right now I am just trying to use print as a message.

    – TrevTV
    Mar 8 at 20:38
















Are you aware that 'a'.format(message) will just return 'a'?

– Mike Holt
Mar 8 at 20:37






Are you aware that 'a'.format(message) will just return 'a'?

– Mike Holt
Mar 8 at 20:37














Yes, I realized that but right now I am just trying to use print as a message.

– TrevTV
Mar 8 at 20:38





Yes, I realized that but right now I am just trying to use print as a message.

– TrevTV
Mar 8 at 20:38












2 Answers
2






active

oldest

votes


















1














You expect msg to be a string, but if you try it:



>>> msg = print("anything at all")
>>> repr(msg)
None


Just remove the print call.






share|improve this answer






























    1














    You should not be using the on_message event to make commands. Use the built-in command handler instead which makes for better program design and efficiency.



    The following code outputs the number you type after !gap



    from discord.ext import commands

    client = commands.Bot(command_prefix='!')

    @client.command(pass_context=True)
    async def gap(ctx, number):
    await client.say(f"ctx.author.mention said the number number")

    client.run("token")


    I also recommend looking into the rewrite branch of the API which has a lot of improvements.






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070583%2fprint-a-variable-output-in-a-400-empty-message-code-using-python%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      You expect msg to be a string, but if you try it:



      >>> msg = print("anything at all")
      >>> repr(msg)
      None


      Just remove the print call.






      share|improve this answer



























        1














        You expect msg to be a string, but if you try it:



        >>> msg = print("anything at all")
        >>> repr(msg)
        None


        Just remove the print call.






        share|improve this answer

























          1












          1








          1







          You expect msg to be a string, but if you try it:



          >>> msg = print("anything at all")
          >>> repr(msg)
          None


          Just remove the print call.






          share|improve this answer













          You expect msg to be a string, but if you try it:



          >>> msg = print("anything at all")
          >>> repr(msg)
          None


          Just remove the print call.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 20:34









          Adam SmithAdam Smith

          35.3k73376




          35.3k73376























              1














              You should not be using the on_message event to make commands. Use the built-in command handler instead which makes for better program design and efficiency.



              The following code outputs the number you type after !gap



              from discord.ext import commands

              client = commands.Bot(command_prefix='!')

              @client.command(pass_context=True)
              async def gap(ctx, number):
              await client.say(f"ctx.author.mention said the number number")

              client.run("token")


              I also recommend looking into the rewrite branch of the API which has a lot of improvements.






              share|improve this answer





























                1














                You should not be using the on_message event to make commands. Use the built-in command handler instead which makes for better program design and efficiency.



                The following code outputs the number you type after !gap



                from discord.ext import commands

                client = commands.Bot(command_prefix='!')

                @client.command(pass_context=True)
                async def gap(ctx, number):
                await client.say(f"ctx.author.mention said the number number")

                client.run("token")


                I also recommend looking into the rewrite branch of the API which has a lot of improvements.






                share|improve this answer



























                  1












                  1








                  1







                  You should not be using the on_message event to make commands. Use the built-in command handler instead which makes for better program design and efficiency.



                  The following code outputs the number you type after !gap



                  from discord.ext import commands

                  client = commands.Bot(command_prefix='!')

                  @client.command(pass_context=True)
                  async def gap(ctx, number):
                  await client.say(f"ctx.author.mention said the number number")

                  client.run("token")


                  I also recommend looking into the rewrite branch of the API which has a lot of improvements.






                  share|improve this answer















                  You should not be using the on_message event to make commands. Use the built-in command handler instead which makes for better program design and efficiency.



                  The following code outputs the number you type after !gap



                  from discord.ext import commands

                  client = commands.Bot(command_prefix='!')

                  @client.command(pass_context=True)
                  async def gap(ctx, number):
                  await client.say(f"ctx.author.mention said the number number")

                  client.run("token")


                  I also recommend looking into the rewrite branch of the API which has a lot of improvements.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 8 at 20:59

























                  answered Mar 8 at 20:52









                  MaryMary

                  614




                  614



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070583%2fprint-a-variable-output-in-a-400-empty-message-code-using-python%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                      Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                      2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived