首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >对不和谐机器人使用Replit

对不和谐机器人使用Replit
EN

Stack Overflow用户
提问于 2021-03-31 18:28:35
回答 1查看 185关注 0票数 0

我制造了一个Groot不和谐的机器人,而且每次有人问它的时候,它都会长出来。每一百个问题,格鲁特就会上升一年。我正在使用replit,在编码方面,我没有那么先进。

代码语言:javascript
运行
复制
import os
import requests
import json
import random



client = discord.Client()

i_am_groot = ("Hey Groot", "Groot", "Twig", "Tree")


client = discord.Client()

groot_age = 0
groot_pings = 100

@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(i_am_groot):
        await message.channel.send('I am groot')
        groot_pings = groot_pings + 1
        groot_age = groot_pings // 100
        await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name='Mr Blue Sky and Dancing | Age: ' + str(groot_age) + ' | Pings: ' + str(groot_pings)))
  if message.content.startswith ('grootage'):
        await message.channel.send ('Translation: ' + str(groot_age))
  if message.content.startswith ('grootpings'):
        await message.channel.send ('Translation: ' + str(groot_pings))



import keep_alive

keep_alive.keep_alive()
    



client.run(os.getenv('TOKEN'))

我知道这个错误:

[pyflakes] local variable 'groot_pings' defined in enclosing scope on line 19 referenced before assignment

定义的。

有办法解决这个问题吗?

帮助?

EN

回答 1

Stack Overflow用户

发布于 2021-04-02 20:33:10

试试下面的代码:

代码语言:javascript
运行
复制
import os
import requests
import json
import random



client = discord.Client()

i_am_groot = ("Hey Groot", "Groot", "Twig", "Tree")


client = discord.Client()

groot_age = 0
groot_pings = 100

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

@client.event
async def on_message(message):
  global groot_age
  global groot_pings
  if message.author == client.user:
        return
  if message.content.startswith(i_am_groot):
        await message.channel.send('I am groot')
        groot_pings = groot_pings + 1
        groot_age = groot_pings // 100
        await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name='Mr Blue Sky and Dancing | Age: ' + str(groot_age) + ' | Pings: ' + str(groot_pings)))
  if message.content.startswith ('grootage'):
        await message.channel.send ('Translation: ' + str(groot_age))
  if message.content.startswith ('grootpings'):
        await message.channel.send ('Translation: ' + str(groot_pings))



import keep_alive

keep_alive.keep_alive()
    



client.run(os.getenv('TOKEN'))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66893317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档