如何向 Discord py 角色限制命令添加拒绝消息
How to add reject message to Discord py role restricted commands
我有这个代码:
import discord
from discord.ext import commands, tasks
import random
from itertools import cycle
from discord.utils import get
import os
bot = commands.Bot(command_prefix='-')
TOKEN = ''
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
@commands.has_role('Admin')
async def test(ctx):
await ctx.send(":smiley: :wave: Hello, there! :heart: ")
bot.run(TOKEN)
如何设置拒绝信息?
我的意思是如果有人使用该命令但他没有管理员角色,机器人会说类似的话
"You aren't admin buddy!"
我已经试过了,但没有用
@bot.command()
@commands.has_role('Admin')
async def test(ctx):
await ctx.send(":smiley: :wave: Hello, there! :heart: ")
else:
await ctx.send("You can't use this!")
当用户调用测试命令但他们没有 'Admin' 角色时,将抛出 commands.MissingRole 错误。你可以用 error handling.
捕捉到这个
import discord
from discord.ext import commands, tasks
import random
from itertools import cycle
from discord.utils import get
import os
TOKEN = ''
bot = commands.Bot(command_prefix='-')
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
@commands.has_role('Admin')
async def test(ctx):
await ctx.send(":smiley: :wave: Hello, there! :heart: ")
@test.error
async def test_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send('''You aren't admin buddy!''')
bot.run('TOKEN')
这会让您在用户没有角色时向他们发送消息。您也可以拥有多个角色而不是管理员。
@bot.command()
async def test(ctx):
if "Admin" in ctx.author.roles:
await ctx.send(":smiley: :wave: Hello, there! :heart: ")
else:
await ctx.send("You are not an admin!")
我有这个代码:
import discord
from discord.ext import commands, tasks
import random
from itertools import cycle
from discord.utils import get
import os
bot = commands.Bot(command_prefix='-')
TOKEN = ''
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
@commands.has_role('Admin')
async def test(ctx):
await ctx.send(":smiley: :wave: Hello, there! :heart: ")
bot.run(TOKEN)
如何设置拒绝信息? 我的意思是如果有人使用该命令但他没有管理员角色,机器人会说类似的话 "You aren't admin buddy!"
我已经试过了,但没有用
@bot.command()
@commands.has_role('Admin')
async def test(ctx):
await ctx.send(":smiley: :wave: Hello, there! :heart: ")
else:
await ctx.send("You can't use this!")
当用户调用测试命令但他们没有 'Admin' 角色时,将抛出 commands.MissingRole 错误。你可以用 error handling.
捕捉到这个import discord
from discord.ext import commands, tasks
import random
from itertools import cycle
from discord.utils import get
import os
TOKEN = ''
bot = commands.Bot(command_prefix='-')
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
@commands.has_role('Admin')
async def test(ctx):
await ctx.send(":smiley: :wave: Hello, there! :heart: ")
@test.error
async def test_error(ctx, error):
if isinstance(error, commands.MissingRole):
await ctx.send('''You aren't admin buddy!''')
bot.run('TOKEN')
这会让您在用户没有角色时向他们发送消息。您也可以拥有多个角色而不是管理员。
@bot.command()
async def test(ctx):
if "Admin" in ctx.author.roles:
await ctx.send(":smiley: :wave: Hello, there! :heart: ")
else:
await ctx.send("You are not an admin!")