简体   繁体   English

如何让我的 discord 机器人从文件中读取并将其粘贴到 discord 聊天命令中?

[英]How to make my discord bot read from a file and paste it in a discord chat on command?

So I am making my discord bot with python and i want my bot to read a notepad file present on my desktop and write everything from the notepad file to the chatbox when the command is typed.因此,我正在使用 python 制作我的 discord 机器人,并且我希望我的机器人读取我桌面上的记事本文件,并在键入命令时将所有内容从记事本文件写入聊天框。 Please tell me how I can do it!请告诉我我该怎么做!

Thanks:-)谢谢:-)

PS Make sure to DM me on discord, if you know how to do it, it would mean the world to me!!!!! PS 一定要在 discord 上给我发消息,如果你知道怎么做,那对我来说就是世界!!!!!! TOG6#6666 TOG6#6666

Here's how to do it, hopefully works!以下是如何做到这一点,希望有效!

@client.command()
async def test(ctx):
    file = open(r"C:\\User\path", "r")
    content = file.read()
    await ctx.send(content)

You don't need to close the file if you're reading it.如果您正在阅读该文件,则无需关闭该文件。

you can read the file like this你可以像这样读取文件

f = open("demofile.txt", "r")
print(f.read())

to post the lines into the discord chat, you have use the discord api要将这些行发布到 discord 聊天中,您必须使用 discord api

your code would help us more.你的代码会帮助我们更多。 Have tried to do anything yet?有没有尝试做任何事情? Maybe try to make your app first and then ask us to help with the specific problems... we cant do the whole app for you:))也许先尝试制作您的应用程序,然后请我们帮助解决具体问题……我们无法为您完成整个应用程序:))

@client.command() async def test(ctx): file = open(r"C:\\User\path", "rt") content = file.read() file.close() await ctx.send(content)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM