![](/img/trans.png)
[英]Sending messages from only 1 channel in Discord (discord.py bot)
[英]Discord.py Bot sending file to Discord Channel
我試圖讓我的不和諧機器人向我的不和諧服務器發送一個 jpg 文件,但我不斷收到一個似乎很不常見的錯誤,因為我在互聯網上找不到任何解決方案......
錯誤是... discord.ext.commands.errors.CommandInvokeError:命令引發異常:ClientRequestError:無法為https://discordapp.com/api/v6/channels/454374995758678029/messages編寫請求正文
我的進口是
import time
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
我將提取的與錯誤相關的代碼是
@bot.command(pass_context = True)
async def image(ctx):
await bot.send_file(ctx.message.channel, open('halogen.jpg'))
我只是缺少導入還是我的代碼存在實際問題?
謝謝你們
我正在研究同樣的事情,我發現這個工作:
await ctx.send(file=discord.File(r'c:\location\of\the_file_to\send.png'))
這是我找到它的地方: 鏈接
嘗試這樣做。
@bot.command(pass_context=True)
async def send(ctx):
area=ctx.message.channel
await bot.send_file(area, r"c:\location\of\the_file_to\send.png",filename="Hello",content="Message test")
您可以在此處參考不和諧文檔鏈接
您可以在沒有 ctx 的情況下發送它:
async def timer():
await client.wait_until_ready()
channel = client.get_channel(number_of_channel)
while True:
await channel.send('Working!', file=discord.File("file.txt"))
await asyncio.sleep(10)#seconds
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.