基本上,我现在为我的机器人准备的代码是创建一个txt频道,并将其保存到我的atom编辑文件所在的文件夹中,该代码看起来像这样:
async def close(ctx):
guild = client.get_guild(742566911778357330)
rolename = 'Administrator'
rolenamestaff = 'Staff'
channel = ctx.channel
channels = ('support')
ticketLogs = discord.utils.get(guild.channels, id=745757663127797850)
role = discord.utils.get(guild.roles, name=rolename)
rolestaff = discord.utils.get(guild.roles, name=rolenamestaff)
overwrites2 = {
guild.default_role: discord.PermissionOverwrite(read_messages= False),
guild.me: discord.PermissionOverwrite(read_messages=True),
ctx.author: discord.PermissionOverwrite(read_messages=False),
rolestaff : discord.PermissionOverwrite(read_messages=False),
role: discord.PermissionOverwrite(read_messages=True)
}
if str(ctx.channel) in channels:{
await ctx.send('You cannot use this command here.')
}
else:
filename = f"{ctx.channel.name}.txt"
with open(filename, "w") as file:
async for msg in ctx.channel.history(limit=None):
file.write(f"{msg.created_at} - {msg.author.display_name}: {msg.clean_content}\n")
area=ticketLogs
await client.send_file(area, r"C:\Users\yoryo\Desktop\Fallback bot",filename=ctx.channel.name)
await channel.edit(overwrites=overwrites2)
我遇到的问题是由于某种原因“机器人”对象没有属性“ send_file” 有任何想法吗?任何帮助将不胜感激。
我也在考虑使用discord.File,但是我不知道如何添加它,如果您知道如何在我的代码中实现discord.File并使所有工作正常,请发布您的答案,它将真的有帮助,谢谢:)
答案 0 :(得分:1)
send_file不存在,请改用channel.send
await channel.send(file=path)
答案 1 :(得分:1)
您必须使用discord.File
await ctx.send(file=discord.File("file.txt"))
或
await channel.send(file=discord.File("file.txt"))