我正在尝试使用 Discord.py 库将消息从一个通道发送到另一个通道。想法 - 通道_1 用户无权读取和发送通道_2 中的消息。我尝试编写应该发送这些消息的机器人 - 例如,用户编写!发送“channel2”“hello”,机器人将此消息发送到通道 2。但是我在尝试执行此操作时遇到错误
import os
import random
import discord
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
token = os.getenv('DISCORD_TOKEN')
bot = commands.Bot(command_prefix='!')
@bot.command(pass_context=True)
async def xsend(ctx, *, message):
await bot.delete_message(ctx.message)
await ctx.send(discord.Object(id='652024045339934731'), message)
bot.run(token)
我收到错误 - TypeError: send() 需要 1 到 2 个位置参数,但给出了 3 个
这不是discord.py-rewrite,对吧?所以只需使用bot.get_channel()
并通过以下方式发送消息bot.send_message()
. 文档链接
(顺便说一句,ctx.send() 会将消息发送到调用的通道,如果我知道的话)
@bot.command(pass_context=True)
async def xsend(ctx, *, message: str):
await bot.delete_message(ctx.message)
channel = bot.get_channel('652024045339934731')
if channel:
await bot.send_message(channel, message)
(discord.py-rewrite 的版本)
@bot.command(pass_context=True)
async def xsend(ctx, *, message: str):
await ctx.message.delete()
channel = bot.get_channel(652024045339934731)
if channel:
await channel.send(message)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)