不和.py通过cons发送消息

2024-04-26 02:57:53 发布

您现在位置:Python中文网/ 问答频道 /正文

好的,我想这样我就可以在一个特定的服务器和通道中从控制台发送消息。我在另一篇文章中看到了如何在特定的服务器和频道上发送消息,但是他们来自discord应用程序而不是控制台。有人能帮我吗?在

我想要,所以我键入msg [server-id-here] [channel-name] [message]例如

msg 493121776402825219 general hello

我有代码,但有错误

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

输出的错误

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


Tags: 服务器应用程序消息message键入onbot错误
2条回答

使用say命令。在

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

   else:
      pass

我不知道这实际上是可能的,但是你可以实现一个新的命令来实现它,这是我为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 :<")

这使得bot在你所说的地方重复你所说的,但是如果你想通过ID向特定的频道发送消息,你可以这样做

^{pr2}$

相关问题 更多 >

    热门问题