简体   繁体   中英

discord.py - Send messages though console

ok, I wanted so I could send messages in an specific server and channel form the console. I seen on other post how to send messages on specific servers and channels but theyr from the discord app and not console. Can someone help me?

I wanted so I type msg [server-id-here] [channel-name] [message] for example

msg 493121776402825219 general hello

Code I have but it has errors

@bot.event
async def on_ready(ch, *, msg):
while msg:
  channel = bot.get_channel(ch)
  msg=input("Mensagem: ")
if channel:
  await bot.send_message(channel, msg)
else:
  await bot.say("I can't find that channel")

Error that outputs

TypeError: on_message() missing 1 required positional argument: 'ch'

I don't this this is actually possible, however you can implement a new command to do it, heres the one I used for welcomer

@bot.command(description="Echos, developers only", pass_context=True)
async def echo(ctx, echowords:str):
    if ctx.message.author.id in []: #put in id's in a list or replace it with one string
        await bot.say(echowords)
    else:
        await bot.say("Bot developers only :<")

This makes the bot repeat what you said where you said it, but if you want to send messages to a specific channel by ID you can do this

@bot.command(description="Echos, developers only", pass_context=True)
async def echo(ctx, id, echowords:str):
    if ctx.message.author.id in []: #put in id's in a list or replace it with one string
        sendchannel = bot.get_channel(id)
        await bot.send_message(sendchannel, echowords)
    else:
        await bot.say("Bot developers only :<")

Use the say command.

@bot.command()
async def say(ctx, *,message):
   if not ctx.author.bot:

   else:
      pass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM