discord.py - Send messages though console

余生颓废 提交于 2020-12-15 05:48:28

问题


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'


回答1:


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 :<")



回答2:


Use the say command.

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

   else:
      pass


来源:https://stackoverflow.com/questions/52464933/discord-py-send-messages-though-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!