【发布时间】:2022-04-05 22:21:09
【问题描述】:
我正在构建一个票务机器人,每次有人对“票证”类别中的消息做出反应时,它都会创建一个频道,如何获取频道 obj 以便机器人可以在那里发送消息?
我有这个:
@client.event
async def on_raw_reaction_add(payload):
channel = client.get_channel(payload.channel_id)
client.get_channel(payload.message_id)
msg = await channel.fetch_message(payload.message_id)
guild = client.get_guild(payload.guild_id)
f = open("ticket_nums.txt", "w+")
overwrites = {
guild.default_role: discord.PermissionOverwrite(read_messages=False),
payload.member: discord.PermissionOverwrite(read_messages=True)
}
if True: #r_msg_id == "720708414107287724": commented out because it doesn't work idk why
if not payload.user_id == "718528256365559829":
await msg.remove_reaction("\U0001f4e8", discord.Object(id=user_id))
await client.get_channel(719621258106372219).create_text_channel(r"ticket#" , overwrites=overwrites)
在打开应该包含票数的ticket_nums文件时,它总是给我这个错误:(每次我尝试打开文件时都会给它)
Traceback (most recent call last):
File "C:\Users\giaco\Desktop\Bot\Discord Bot\bot_discord.py", line 216, in on_raw_reaction_add
f = open("ticket_nums.txt", "w+")
PermissionError: [Errno 13] Permission denied: 'ticket_nums.txt'
【问题讨论】:
标签: python discord discord.py