繁体   English   中英

如何使用 Discord.Py 在 Python 中修复此属性错误

[英]How do I fix this Attribute error in Python with Discord.Py

我目前正在尝试制作一个运行 python 代码的不和谐机器人。 我已经快完成了,但是在第 19 行遇到了属性错误

确切的错误是:属性错误:'str'没有属性'exec'

import discord

def run_code_func(String_to_run):
  String_to_run.replace("`", "")
  String_to_run.lstrip("python")
  (String_to_run.rstrip("`"))
  String_to_run.exec()
client = discord.Client()

@client.event
async def on_ready():
  print("We have logged in as {0.user}".format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return

  if message.content.startswith("```python"):
    run_code = message.content
    run_code_func(run_code)
    


    


client.run("Secret")

谢谢您的帮助!

没有str.exec这样的东西,如果你想将字符串作为代码执行,请使用exec(String_to_run)

暂无
暂无

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

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