Discord.py改变存在

时间:2018-04-22 16:07:25

标签: python discord discord.py

您好我正在制作机器人,我想改变存在

我一直收到错误我希望有人可以告诉我我做错了什么

import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import chalk
import requests
import random

#Bot token
bottoken = "snip"
#Bot command prefix
commandprefix = "#"

bot = commands.Bot(command_prefix=commandprefix)

@bot.event
async def on_ready():
    print ("Starting up")
    print ("My username is " + bot.user.name + " and i am running with the ID: " + bot.user.id)
    await self.bot.change_presence(game=discord.Game(name="Test", type=1))
    print ("Started")

change_presence( game=None, status=None, afk=False)

@bot.command(pass_context=True)
async def hello(ctx):
    await bot.say("hi")
    print ("hi Posted")

bot.run(bottoken)

和错误

Traceback (most recent call last):

File "thefilelocationonmypc", line 64, in <module>

change_presence( game=None, status=None, afk=False)

NameError: name 'change_presence' is not defined

3 个答案:

答案 0 :(得分:1)

现在您正在尝试调用名为change_presence的函数。因为您没有定义该函数,所以您收到该错误。

您需要await bot.change_presence代替change_presence才能使用discord.py的change_presence功能

答案 1 :(得分:1)

您没有定义 change_presence 函数。 要使其工作,请执行以下操作:

async def change_presence():
 print ("Starting up")
 print ("My username is " + bot.user.name + " and i am running with the ID: " + bot.user.id)
 await bot.change_presence(game=discord.Game(name="Test", type=1))
 print ("Started")

change_presence();

希望对你有帮助! :)

答案 2 :(得分:-1)

工作代码:

import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import requests
import random

bottoken = "snip"
commandprefix = "#"

bot = commands.Bot(command_prefix=commandprefix)


@bot.event
async def on_ready():
    print ("Starting up")
    print ("My username is " + bot.user.name + " and i am running with the ID: " + bot.user.id)
    await bot.change_presence(game=discord.Game(name="Test", type=1))
    print ("Started")


@bot.command(pass_context=True)
async def hello(ctx):
    await bot.say("hi")
    print ("hi Posted")


bot.run(bottoken)