[英]Problem with Auto Role Function in discord.py
I am writing an auto role function for a Discord server but it is not functioning as intended.我正在为 Discord 服务器编写自动角色 function,但它没有按预期运行。 Any info would help.
任何信息都会有所帮助。 Here is my code, it is being run on Python 3.7 on raspberry Pi.
这是我的代码,它在树莓派上的 Python 3.7 上运行。 (Edit2: Revised the code but there still is not anything happening, I imported the DiscordUtils library to add more functions ).
(Edit2:修改了代码但仍然没有发生任何事情,我导入了 DiscordUtils 库以添加更多功能)。
import random
import discord
from discord.ext import commands
import DiscordUtils
TOKEN = 'TOKEN'
description = '''Bonzi Buddy Stealer of Memes'''
bot = commands.Bot(command_prefix='?', description=description)
role = 'level 1'
client = discord.Client()
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
await bot.change_presence(activity=discord.Game(name="Waluigi for Atari 2600"))
@bot.event
async def on_command_error(ctx, error):
user = ctx.message.author
await ctx.send(f"An error occured: {str(error)}")
print(ctx.message.author)
@bot.event
async def on_member_join(member):
role = discord.utils.get(member.server.roles, id="787454585731284992")
await bot.add_roles(member, role)
@bot.command()
async def hello(ctx):
"""Says world"""
user = ctx.message.author
await ctx.send("world")
print(ctx.message.author)
@bot.command()
async def add(ctx, left : int, right : int):
"""Addition"""
user = ctx.message.author
await ctx.send(left + right)
print(ctx.message.author)
@bot.command()
async def subtract(ctx, left : int, right : int):
"""Subtraction"""
user = ctx.message.author
await ctx.send(left - right)
print(ctx.message.author)
@bot.command()
async def multiply(ctx, left : int, right : int):
"""Multiplication"""
user = ctx.message.author
await ctx.send(left * right)
print(ctx.message.author)
@bot.command()
async def divide(ctx, left : int, right : int):
"""Division"""
user = ctx.message.author
await ctx.send(left / right)
print(ctx.message.author)
@bot.command()
async def joke(ctx):
"""Unfunny Joke"""
user = ctx.message.author
await ctx.send(random.choice(jokes))
print(ctx.message.author)
@bot.command()
async def sayuser(ctx):
"""get user name"""
user = ctx.message.author
await ctx.send("mention: " + user.mention + " name: " + user.name)
print(ctx.message.author)
@bot.command()
async def mario(ctx):
"""RUN"""
user = ctx.message.author
await ctx.send("https://cdn.discordapp.com/attachments/731930062777221171/794807999096684584/video0_67.mp4")
print(ctx.message.author)
@bot.command()
async def betaGif(ctx):
"""NULL"""
user = ctx.message.author
await ctx.send(random.choice(gifs))
print(ctx.message.author)
#@bot.command()
#async def gif(ctx):
#ctx.send(file=discord.File('squidward.gif'))
jokes = ["What do you call a Cow that can\'t give milk? An utter faliure!",
"What do Donkeys send out near Christmas? Mule tide greetings!",
"Who earns a living by driving his customers away? A Taxi Driver!",
"What question can never be answered by yes? Are you asleep?",
"Why do they call HTML hyper text? Too much Java!",
"When is the best time to got to bed? When the bed won\'t come to you!"]
gifs = ["https://media.discordapp.net/attachments/817586768827121666/836011336437727262/image0.gif",
"https://tenor.com/view/jontron-just-let-me-die-flex-tape-im-too-perfect-let-me-die-gif-13374794",
"https://tenor.com/view/tf2-spy-spy-tf2-gentlemen-gif-18144778"]
bot.run(TOKEN)
if __name__ == "__main__":
run()
Ok a few errors I found:好的,我发现了一些错误:
embed
isn't defined in line 2 embed
未在第 2 行中定义defualtrole
must be a string or a variable which I don't see defualtrole
必须是我看不到的字符串或变量get
isn't defined get
未定义
This was before the edit ^这是在编辑之前^
get
isn't defined. get
没有定义。 You probably want discord.Utils.get
and add the defualtRole
to the function scope so it isnt global.您可能想要
discord.Utils.get
并将defualtRole
添加到 function scope 所以它不是全局的。
What is your error right now though?你现在的错误是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.