简体   繁体   English

为什么我的不和谐机器人不会在频道 discord.py 中发送消息

[英]Why will my discord bot not send a message in a channel discord.py

My python discord bot keeps getting errors when I tell it to send a message in a channel当我告诉它在频道中发送消息时,我的 python discord bot 不断出错

@client.command()
async def log(ctx, msg):
channel = client.get_channel(852610465871036416)
await channel.message.send(msg)

PS: its fixed now PS:现在修复了

Try This:试试这个:

@client.command()
async def log(ctx, msg):
  await ctx.send(msg)

I'm Pretty Sure You Needed to Use ctx.send我很确定你需要使用 ctx.send

Tortle.py is completely right, however, you can do many forms of the ctx.___("stuff") . Tortle.py 是完全正确的,但是,您可以执行多种形式的ctx.___("stuff") The first and simplest example would be ctx.send("stuff") , this will send the "stuff" in the channel where the user called the function (the thing the bot is doing.)第一个也是最简单的例子是ctx.send("stuff") ,这将在用户调用函数的通道中发送“stuff”(机器人正在做的事情)。

You could also do ctx.author.send this will DM (direct message) the author that called the function.您也可以执行ctx.author.send这将 DM(直接消息)调用该函数的作者。

You could also do ctx.reply this will reply to the message that the user sends.您也可以执行ctx.reply这将回复用户发送的消息。

I hope you found this useful and feel free to like on this message for any extra support!我希望你觉得这很有用,并随时喜欢这条消息以获得任何额外的支持!

in last line在最后一行

await channel.message.send(msg)

? ?
try it尝试一下

await channel.send(msg)
@client.command()
async def log(ctx, message):
   await ctx.get_channel(852610465871036416).send(“your message”)

This would work这会工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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