在多行上发送消息

发布于 2025-02-01 22:24:02 字数 585 浏览 4 评论 0原文

我试图获取我的工具以自动在Discord服务器中发送消息,但是,我的消息不止一行。我尝试使用将其全部放入一行,然后使用“ \ n”来获取新行。但这不起作用。它仅读取整个消息的底部消息。我将消息输入邮件。txt,因此用户不必编辑程序。 这是函数 +发送消息函数

    def loadmessages():
lines = []
with open('messages.txt') as f:
    lines = f.readlines()
#had trouble formatting code

定义

def send_messages(message_data,):
connection = get_connection()
m=dumps(message_data)
with open("Channel ID's.txt","r") as f:
    ChannelIDs = f.read().split("\n")
for channel in ChannelIDs:
    send_message(connection, channel,m,)
    sleep(5)
    repeat()

Im trying to get my tool to send a message automatically in discord servers, However, My message is more than one line. I tried using putting it all in one line and using '\n' to get a new line. But that doesn't work. It only reads the bottom message of the entire message. I have the message put in a message.txt so the user doesn't have to edit the programme.
Here's the definition of the function + the send message function, LMK if you need anything else

#Message

    def loadmessages():
lines = []
with open('messages.txt') as f:
    lines = f.readlines()
#had trouble formatting code

#Send message

def send_messages(message_data,):
connection = get_connection()
m=dumps(message_data)
with open("Channel ID's.txt","r") as f:
    ChannelIDs = f.read().split("\n")
for channel in ChannelIDs:
    send_message(connection, channel,m,)
    sleep(5)
    repeat()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠佳期 2025-02-08 22:24:02

您随时可以将文件的文本读为变量。例如:

message = ""

with open('messages.txt', 'r+') as f:

  for line in f.readlines():
        message+=line

You can always read a text of a file into variable. For example:

message = ""

with open('messages.txt', 'r+') as f:

  for line in f.readlines():
        message+=line
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文