python - Discord PY 无法更改发送消息的通道
问题描述
我正在使用 Discord py,但我无法更改发送消息的频道,它是如何工作的:首先我使用命令 !set_channel 设置频道 ID,此 ID 保存在 txt 文档中,之后我使用命令“ !say bla bla”,并且此消息在上一个命令中发送到我设置的频道,在此命令执行之前,我正在切割不需要的垃圾,例如“()”,因为我认为这个垃圾破坏了我的代码。如果我没有剪切代码,这将看起来像“('824312123131822092',)”。当我尝试在设置的频道中发送消息时,我不明白为什么我得到“无”。
- 是的,我已将我的不和谐机器人添加到我的服务器,我的机器人仅在我的服务器上。
- 是的,我的频道已创建,并且我设置了正确的 ID。
@bot.command()
async def say(msg, *arg):
file1 = open("channel.txt", "r")
output = file1.read()
file1.close()
replaced_output = output.replace("'", "")
replaced_output2 = replaced_output.replace("(", "")
replaced_output3 = replaced_output2.replace(")", "")
replaced_output4 = replaced_output3.replace(",", "")
channel = bot.get_channel(replaced_output4)
author = msg.author.id
if str(author) != str(owner):
embed = discord.Embed(description=f"<@{author}> ```You not have rights.```", colour=COLOR)
await msg.channel.send(embed=embed)
return
else:
if not arg:
embed = discord.Embed(description="Required argument after !say", colour=COLOR)
embed.set_author(name="Omega Software",icon_url=msg.guild.icon_url)
embed.set_footer(text="Created for fun!")
await msg.channel.send(embed=embed)
else:
embed = discord.Embed(description=" ".join(arg), colour=COLOR)
embed.set_author(name="Omega Software",icon_url=msg.guild.icon_url)
embed.set_footer(text="Created for fun!")
print (channel)
print (replaced_output4)
if channel:
await channel.send(embed=embed)
return
解决方案
推荐阅读
- c++ - std::is_member_function_pointer 不适用于 noexcept 成员函数
- javascript - 给定元素的特定索引,如何替换数组中的元素?
- android - Kotlin:如何将子数组减少为单个数组?
- reactjs - 根据表格内容动态设置列宽
- safari - 如何为 302 重定向的 url 启用 Safari 浏览器缓存
- java - Java 到 Arduino 的通信不同步 - 跳跃运动
- python - NameError: [class] 未定义
- c - 如何返回字符指针?
- python - pandas - DataError 没有要聚合的数字类型
- java - 需要触发 JavaFX TableView 的内置 Table Menu Button